Skip to content

Instantly share code, notes, and snippets.

@brainrake
Created January 31, 2017 11:39
Show Gist options
  • Save brainrake/9e32b662d49741c90bf42ba19d188c7a to your computer and use it in GitHub Desktop.
Save brainrake/9e32b662d49741c90bf42ba19d188c7a to your computer and use it in GitHub Desktop.
head of empty list in haskell
main = print $ show $ head []
> nix-shell -p ghc --run 'ghc a.hs'
[1 of 1] Compiling Main ( a.hs, a.o )
a.hs:1:16: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘show’
prevents the constraint ‘(Show a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
...plus 22 others
...plus five instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the second argument of ‘($)’, namely ‘show $ head []’
In the expression: print $ show $ head []
In an equation for ‘main’: main = print $ show $ head []
> nix-shell -p ghc --run 'ghc -e "print $ show $ head []"'
<interactive>: Prelude.head: empty list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment