I have the following statement:
Prelude> :t error "Hello"
error "Hello" :: a
that I would like to know, what is the type of a
?
a
is a type variable, one that could be unified with any concrete type you like. Want to add error "Hello"
to an Integer
? OK.
> :t error "Hello" + (3 :: Integer)
error "Hello" + (3 :: Integer) :: Integer
Want to prepend a Maybe Char
value? No problem.
> :t Just 'c' : error "Hello"
Just 'c' : error "Hello" :: [Maybe Char]
Whatever you want a
to be, error
will tell you it can return a value of that type.
Of course, this is a moot point, because error
will never actually return.
> error "Hello" + (3 :: Integer)
*** Exception: Hello
CallStack (from HasCallStack):
error, called at <interactive>:3:1 in interactive:Ghci1
> Just 'c' : error "Hello"
[Just 'c'*** Exception: Hello
CallStack (from HasCallStack):
error, called at <interactive>:4:12 in interactive:Ghci1
Especially in the last one: ghci
starts to output a value of type [Maybe Char]
, and succeeds at outputting the first element, because (:)
is non-strict in its second element. Not until an attempt is actually made to get the second value does error "Hello"
get evaluated and its "bluff" is called. Rather than being able to match it against either []
or (:)
, a runtime exception occurs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With