Importing Control.Arrow changes inferred type of (m >>= f) x in ghci

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Importing Control.Arrow changes inferred type of (m >>= f) x in ghci

Dan Weston
The following inferred type has a constraint that can be trivially
satisfied, but isn't:

Control.Monad> :t \ (m,f,x) -> (m >>= f) x
\ (m,f,x) -> (m >>= f) x
   :: forall t a b. (Monad ((->) t)) => (t -> a, a -> t -> b, t) -> b

-- In Control.Monad there is forall t. instance Monad ((->) t),
-- so why is the vacuous Monad constraint still there?
-- Nor can I remove it with a type annotation:

Control.Monad> :t \ (m,f,x) -> (m >>= f) x :: forall t a b. (t -> a, a
-> t -> b, t) -> b

<interactive>:1:13:
     Inferred type is less polymorphic than expected
     [snip]

-- Then if I just import a module:
Control.Monad> :m + Control.Arrow

-- Now, the Monad ((-> t) constraint disappears:

Control.Monad Control.Arrow> :t \ (m,f,x) -> (m >>= f) x
\ (m,f,x) -> (m >>= f) x
   :: forall t a b. (t -> a, a -> t -> b, t) -> b

-- Although it still will not accept an explicit type annotation:
Control.Monad Control.Arrow> :t \ (m,f,x) -> (m >>= f) x :: forall t a
b. (t -> a, a -> t -> b, t) -> b

<interactive>:1:13:
     Inferred type is less polymorphic than expected
    [snip]


Is there some explicit kind annotation I can/should give to get the most
general type?

Dan

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Importing Control.Arrow changes inferred type of (m >>= f) x in ghci

Luke Palmer-2
On Mon, Jul 27, 2009 at 7:58 PM, Dan Weston<[hidden email]> wrote:

> The following inferred type has a constraint that can be trivially
> satisfied, but isn't:
>
> Control.Monad> :t \ (m,f,x) -> (m >>= f) x
> \ (m,f,x) -> (m >>= f) x
>  :: forall t a b. (Monad ((->) t)) => (t -> a, a -> t -> b, t) -> b
>
> -- In Control.Monad there is forall t. instance Monad ((->) t),
> -- so why is the vacuous Monad constraint still there?
> -- Nor can I remove it with a type annotation:

That instance is in the annoying module Control.Monad.Instances.

>
> Control.Monad> :t \ (m,f,x) -> (m >>= f) x :: forall t a b. (t -> a, a -> t
> -> b, t) -> b
>
> <interactive>:1:13:
>    Inferred type is less polymorphic than expected
>    [snip]
>
> -- Then if I just import a module:
> Control.Monad> :m + Control.Arrow

Presumably it is also here.

>
> -- Now, the Monad ((-> t) constraint disappears:
>
> Control.Monad Control.Arrow> :t \ (m,f,x) -> (m >>= f) x
> \ (m,f,x) -> (m >>= f) x
>  :: forall t a b. (t -> a, a -> t -> b, t) -> b
>
> -- Although it still will not accept an explicit type annotation:
> Control.Monad Control.Arrow> :t \ (m,f,x) -> (m >>= f) x :: forall t a b. (t
> -> a, a -> t -> b, t) -> b

This is just because :: binds tighter than lambda, I think:

>>> :t (\(m,f,x) -> (m >>= f) x) :: forall t a b. (t -> a, a -> t -> b, t) -> b

typechecks just fine.

Luke
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe