5 ms·
$ cat maybe.hs handleMaybeNum :: Maybe int -> int handleMaybeNum Just a = a $ ghci maybe.hs GHCi, version 7.10.3: http://www.haskell.org/ghc/
by tom_mellior 8y ago
$ cat maybe.hs
handleMaybeNum :: Maybe int -> int
handleMaybeNum Just a = a
$ ghci maybe.hs
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( maybe.hs, interpreted )
maybe.hs:2:16:
Constructor ‘Just’ should have 1 argument, but has been given none
In the pattern: Just
In an equation for ‘handleMaybeNum’: handleMaybeNum Just a = a
Failed, modules loaded: none.
You're right about the "precompile time error", although it's not what you claim...
Let's fix the syntax error:
$ cat maybe_fixed.hs
handleMaybeNum :: Maybe int -> int
handleMaybeNum (Just a) = a
$ ghci maybe_fixed.hs
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( maybe_fixed.hs, interpreted )
Ok, modules loaded: Main.
*Main>
No error now. You do get a warning with -Wall, but that's not quite what you claimed. (Newer versions may be more strict, I don't know.)
- crimsonalucard 8y agoHmm my mistake. The match operator in rust is exhaustive though and will raise a compile time error rather than a warning. Elm does this as well. I'm just getting mixed up.
- tom_mellior 8y agoYeah, I think it's the same for OCaml. I found it funny that Haskell would be the odd one out here.