7 ms·
For comparison, in Haskell you would get for this definition: myfun :: Int -> Char -> Bool myfun a b = undefined if you give too many arguments:
by nh2 4y ago
For comparison, in Haskell you would get for this definition:
myfun :: Int -> Char -> Bool
myfun a b = undefined
if you give too many arguments:
myfun 1 'c' 3
• Couldn't match expected type ‘t0 -> t’ with actual type ‘Bool’
• The function ‘myfun’ is applied to three value arguments,
but its type ‘p10 -> Char -> Bool’ has only two
if you give too few arguments:
putStrLn (myfun 1)
• No instance for (Show (p20 -> Bool))
arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
I like how it says
applied to three value arguments ... but its type ... has only two
and
maybe you haven't applied a function to enough arguments?
- earth_walker 4y agoElm's developers have been working hard to make better error messages for these cases, and it really pays off even when experienced. Here are Elm's versions for comparison: > myfun 1 'c' 3 -- TOO MANY ARGS ---------------------------------------------------------- REPL The `myfun` function expects 2 arguments, but it got 3 instead. 5| myfun 1 'c' 3 ^^^^^ Are there any missing commas? Or missing parentheses? > not (myfun 1) -- TYPE MISMATCH ---------------------------------------------------------- REPL The 1st argument to `not` is not what I expect: 5| not (myfun 1) ^^^^^^^ This `myfun` call produces: a -> Bool But `not` needs the 1st argument to be: Bool Besides being 'beginner friendly', this just takes away cognitive overhead when you can glance at an error message and immediately know what happened. (Edit: Formatting. Note that in the console output the arrows actually line up with the source of the errors)