[Haskell-cafe] Unable to correctly infer function type, via pattern matching?

Amos Robinson amos.robinson at gmail.com
Mon Aug 15 03:29:50 UTC 2016


Hi,
I think the problem is that when you give functions in where clauses type
signatures, type parameters like "a" are bound by forall. So the "a" in h
is a different one to in "g".
You might have more luck if you enable -XScopedTypeVariables , and give a
top-level type signature explicitly binding a and b: "forall a b. Stream a
-> …"

On Mon, 15 Aug 2016 at 13:04 David Banas <capn.freako at gmail.com> wrote:

> Hi all,
>
> I wonder if anyone can help me find my error, in this code:
>
> It’s note clear to me why x :: a is an error, except that maybe the type
> of f is not being correctly inferred?
> Am I, maybe, not allowed to use pattern matching, on the right side of ‘=‘?
>
> Thanks,
> -db
>
>
> data Stream a = Cons a (Stream a)
>
> newtype StreamMap a b = SM (Stream a -> Stream b)
>
> instance Arrow StreamMap where
>     pure f        = SM g
>      where g (Cons x xs) = Cons (f x) (g xs)
>     SM f >>> SM g = SM (g . f)
>     first (SM g)  = SM h  -- h :: Stream (a, c) -> Stream (b, c)
>      where h :: Stream (a, c) -> Stream (b, c)
>            h (Cons (x, y) zs) = Cons ((f x), y) (h zs)
>            g :: Stream a -> Stream b
>            g (Cons x      xs) = Cons (f x) (g xs)
>
>
> Couldn't match expected type ‘b1’ with actual type ‘a’
> ‘a’ is a rigid type variable bound by the type signature for g ::
> interactive:IHaskell152.Stream a -> interactive:IHaskell152.Stream b1 at
> :10:17
> ‘b1’ is a rigid type variable bound by the type signature for g ::
> interactive:IHaskell152.Stream a -> interactive:IHaskell152.Stream b1 at
> :10:17
> Relevant bindings include
> xs :: interactive:IHaskell152.Stream a (bound at :11:27)
> x :: a (bound at :11:20)
> g :: interactive:IHaskell152.Stream a -> interactive:IHaskell152.Stream b1
> (bound at :11:12)
> In the first argument of ‘f’, namely ‘x’
> In the first argument of ‘IHaskell152.Cons’, namely ‘(f x)’
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160815/e2c1726c/attachment.html>


More information about the Haskell-Cafe mailing list