Skip to content

Instantly share code, notes, and snippets.

@carlosgaldino
Created April 18, 2014 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosgaldino/11023688 to your computer and use it in GitHub Desktop.
Save carlosgaldino/11023688 to your computer and use it in GitHub Desktop.
type inference in haskell
lengthOf x
| length x == 0 = "0"
| otherwise = length x
{--
lengthOf.hs:3:17:
Couldn't match expected type `[Char]' with actual type `Int'
In the return type of a call of `length'
In the expression: length x
In an equation for `lengthOf':
lengthOf x
| length x == 0 = "0"
| otherwise = length x
--}

The point here is that even though Haskell is a static language, you don't need to specify the types because its type system can infer the types and know that you are doing something wrong.

Another interesting fact is the error message itself. It is pretty straightforward to understand what is the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment