3 ms·
Not quite. sh-4.3$ cat test.hs main = let x = Nothing in case x of Just x -> putStrLn "something" sh-4.3$ ghc test.hs
by VMG 12y ago
Not quite.
sh-4.3$ cat test.hs
main = let x = Nothing
in case x of
Just x -> putStrLn "something"
sh-4.3$ ghc test.hs
sh-4.3$ ./test
test: test.hs:(2,11)-(3,40): Non-exhaustive patterns in case
- striking 12y agoAh, so it will compile but break, thank you for mentioning that.
- dllthomas 12y agoAlternatively, sh-4.3~$ ghc -Wall -Werror test.hs [1 of 1] Compiling Main ( test.hs, test.o ) test.hs:1:1: Warning: Top-level binding with no type signature: main :: IO () test.hs:3:16: Warning: This binding for `x' shadows the existing binding bound at test.hs:1:12 test.hs:3:16: Warning: Defined but not used: `x' <no location info>: Failing due to -Werror.
- VMG 12y agoThis is where it gets weird on my system sh-4.3$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.3 sh-4.3$ ghc -Wall -Werror test.hs sh-4.3$ Arch Linux 64bit. It works as expected with runhaskell though Edit: see answer below, thanks dilthomas!
- dllthomas 12y agoTry touching test.hs (or add -fforce-recomp). By default, ghc won't rebuild if the object is newer than the source.
- luchs 12y agoBut it doesn't break because of the "Non-exhaustive patterns in case" that causes the runtime failure? These things look like they can be fixed without touching the case statement.