[Haskell-cafe] New type of expressions containing (error ...) includes noisy implicit parameter

Eric Seidel eric at seidel.io
Sat Feb 13 17:18:07 UTC 2016


Here's what the GHCi session should look like.

> $ ghci
> GHCi, version 8.0.0.20160204: http://www.haskell.org/ghc/  :? for help
> Loaded GHCi configuration from /home/callen/.ghci
> Prelude> let myList = [1..5 :: Integer]
> Prelude> let myList' = myList ++ undefined
> Prelude> :t myList'
> myList' :: HasCallStack => [Integer]

If your readers are using :t they must already know about simple types
like Integer, [], and, ->, so the new things are HasCallStack and =>.
This is how I would explain them.

  => is just like -> except the compiler fills in the argument by
  itself. 
  HasCallStack tells the compiler that the expression needs a call-stack 
  because it might crash. So HasCallStack => [Integer] is a [Integer]
  that
  might crash and produce a stack-trace.

I think the call-stacks are much less scary and confusing than
type-classes in general, which you kind of have to deal with as soon as
you talk about arithmetic.

Eric


More information about the Haskell-Cafe mailing list