[Haskell-beginners] Type signatures returned with :t

Erik Dominikus erik.dominikus71 at gmail.com
Sun Sep 19 12:54:30 UTC 2021


> are both straightforward parameterized types, but Maybe doesn't give me a
type parameter back, while Either does, and in different order, different
names (a becomes b; b becomes a) depending on which variable I invoke.

Try these diagnostics:

--- Diagnostic 1

Given that the type of "const" is "a -> b -> a" and the type of "True" is
"Bool":

:t const
const :: a -> b -> a

:t True
True :: Bool

What do you expect the type of "const True" to be?

:t const True
const True :: <what do you think goes here?>

   - If you answer "b -> Bool", you are correct, so you may be confused by
   the data type definition syntax (see below).
   - If you answer something else, you may be missing some basic
   understanding of the type system.


--- Diagnostic 2

Consider this case:

:t id
id :: a -> a

:t (id, id)
(id, id) :: (a1 -> a1, a2 -> a2)

   - If you think that the type of "(id, id)" should be "(a -> a, a -> a)",
   you may be unaware of the implicit universal quantifiers.


--- If you are confused by the data type definition syntax:

data Either a b
  = Left a
  | Right b

then, consider the GADT (generalized algebraic data type) definition syntax
for saying the same thing:

data Either a b where
  Left  :: a -> Either a b
  Right :: b -> Either a b

The problem becomes less confusing: The GADT definition syntax is screaming
that "Left" is a function like "id", "const", etc.

---

If you're still unsure, try thinking aloud here: Write your expectations
and why you think so (your thought process, what steps you took to arrive
at your expectations).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210919/30018e68/attachment.html>


More information about the Beginners mailing list