On Thursday, February 16, 2017 at 2:59:41 PM UTC, Rupert Smith wrote: > > On Thursday, February 16, 2017 at 2:50:10 PM UTC, Martin Cerny wrote: >> >> I would say not type checking your example is correct behavior. Since all >> occurrences of a type parameter have to resolve to the same type, the value >> of test is not defined if b resolves to anything other than String. And >> thus the compiler expects you to say it is a string. To be more specific, >> if your code would compile, the following would also compile, which is bad: >> >> intToString: Int -> String >> intToString a = >> "Value:" ++ (toString a) >> >> err: Int->Int >> err = >> test (Specific intToString) >> >> showError:Int >> showError = >> err 5 --Now I am casting a string "Value:5" to int. >> >> > > I think you got the type of the 'err' function wrong? It would be Int -> > String (as it applies test to a Val Int String). So err 5 would be > "Value:5", a String as expected. >
Sorry, my bad, but its easy to get confused. You are right, "Specific intToString" has type "Val Int b", you then bound b to Int in the type spec for err, so it does have the type "Int -> Int". So the problem is that using the MGU would allow under-specified return types which can then be coerced into the wrong type leading to a runtime error. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
