clojure - Why do Haskell inferred types in return type polymorphism lead to runtime errors? -
Because of this I want to use Haskell because this gives me more information about my program at compiled time , By which I believe that this is the sound.
In addition, it will appear that Haskell is the optimum language in which to reach, (unlike the closure protocol - which can only be transmitted on the first argument).
When I find a Haskell polymorphic return value function such as read :
Read :: (read one) => String - & gt; A with the following program:
addFive :: int - & gt; Int addFive x = x + 5 Main :: IO () Main = Print (Adfive (read "11") putStrLn (read "11") I'm getting:
Runtime error ... program: prelog. Read: no parse So I get a runtime error in a language with a better type of system.
(add-five [x] (+ 5 x) defln (println (add-five (read string), with the equivalent code in the closure "11"))) (printline (reading-string "11")) gives:
16 11 My question Why do the change in type of variation in the predicted types lead to runtime errors? Should not they take them in compiling time?
read type
(read one) = & Gt; String -> A Which means it (compiler or interpreter, in fact) will select its return type according to the reference requirement.
Therefore, in addFive (Read "11") , because addFive requires a int , by compiler Selected read to string - & gt; Int ; In putStrLn (read "11") , it will be string-> string because putStrLn is a string .
And this option happens at compile time, which means after compiling, the equivalent of your program
main = do print (addFive (readInt "11" )) PutStrLn (ReadString "11") but it can not parse its argument as readString string "11" , So it crashes at run time.
The fix for this problem is simple:
main = print (adfify (read "11")) putStrLn (read "\" 11 \ "")
Comments
Post a Comment