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 with the following program: I'm getting: So I get a runtime error in a language with a better type of system. gives: 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? Which means it (compiler or interpreter, in fact) will select its return type according to the reference requirement. Therefore, in And this option happens at compile time, which means after compiling, the equivalent of your program but it can not parse its argument as The fix for this problem is simple: read :
Read :: (read one) => String - & gt; A
addFive :: int - & gt; Int addFive x = x + 5 Main :: IO () Main = Print (Adfive (read "11") putStrLn (read "11")
Runtime error ... program: prelog. Read: no parse
(add-five [x] (+ 5 x) defln (println (add-five (read string), with the equivalent code in the closure "11"))) (printline (reading-string "11"))
16 11
read type
(read one) = & Gt; String -> A
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 .
main = do print (addFive (readInt "11" )) PutStrLn (ReadString "11")
readString string
"11" , So it crashes at run time.
main = print (adfify (read "11")) putStrLn (read "\" 11 \ "")
Comments
Post a Comment