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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe