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

David Banas capn.freako at gmail.com
Mon Aug 15 03:04:10 UTC 2016


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)’

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160814/43662913/attachment.html>


More information about the Haskell-Cafe mailing list