[Haskell-cafe] What's the problem with iota's type signature?

michael rice nowgate at yahoo.com
Thu May 28 01:40:04 EDT 2009

```Yeah, I went back and tried double again, though I'd swear I got the dang thing to compile  (and run) w/o errors.

I guess I meant Num. So Num is a class and Int and Integer are types? What are the other classes? Docs?

Unification, for me, is pattern matching ala Prolog. What's the meaning in Haskell? Docs?

I've been digging into this stuff for months and it's still tripping me up. Very frustrating.

Thanks.

Michael

--- On Thu, 5/28/09, wren ng thornton <wren at freegeek.org> wrote:

From: wren ng thornton <wren at freegeek.org>
Subject: Re: [Haskell-cafe] What's the problem with iota's type signature?
Date: Thursday, May 28, 2009, 12:40 AM

michael rice wrote:
> Still exploring monads. I don't understand why the type signature for double is OK,

It isn't. The |a| and |b| variables must unify:

Prelude> :t \x -> Just (x+x)
\x -> Just (x+x) :: (Num a) => a -> Maybe a

Prelude> :t (\x -> Just (x+x)) :: Num a => a -> Maybe b
<interactive>:1:13:
Couldn't match expected type `b' against inferred type `a'
`b' is a rigid type variable bound by
the polymorphic type `forall a b. (Num a) => a -> Maybe b'
at <interactive>:1:0
`a' is a rigid type variable bound by
the polymorphic type `forall a b. (Num a) => a -> Maybe b'
at <interactive>:1:0
In the first argument of `Just', namely `(x + x)'
In the expression: Just (x + x)

> but not the one for iota.

Again the |a| and |b| must unify.
Also, Int isn't a type class (did you mean Num?)
Also, the use of (..) requires the Enum class.

Prelude> :t \n -> [1..n]
\n -> [1..n] :: (Enum t, Num t) => t -> [t]

Prelude> [3,4,5] >>= (\n -> [1..n])
[1,2,3,1,2,3,4,1,2,3,4,5]

-- Live well,
~wren
_______________________________________________