Francesco Mazzoli | 19 Jun 12:25 2013
Picon

GADTs and pattern matching

Hi list,

I had asked this on haskell-cafe but this looks particularly fishy, so
posting here in case it is an issue:

    {-# LANGUAGE GADTs #-}

    data Foo v where
        Foo :: forall v. Foo (Maybe v)

    -- Works
    foo1 :: Foo a -> a -> Int
    foo1 Foo Nothing  = undefined
    foo1 Foo (Just x) = undefined

    -- This works
    foo2 :: a -> Foo a -> Int
    foo2 x Foo = foo2' x

    foo2' :: Maybe a -> Int
    foo2' Nothing = undefined
    foo2' (Just x) = undefined

    -- This doesn't!
    foo3 :: a -> Foo a -> Int
    foo3 Nothing  Foo  = undefined
    foo3 (Just x) Foo = undefined

So it looks like constraints in pattern matching only propagate
forwards.  Is this intended?
(Continue reading)

Francesco Mazzoli | 19 Jun 13:00 2013
Picon

Re: GADTs and pattern matching

At Wed, 19 Jun 2013 11:25:49 +0100,
Francesco Mazzoli wrote:
> 
> Hi list,
> 
> I had asked this on haskell-cafe but this looks particularly fishy, so
> posting here in case it is an issue:
> 
>     {-# LANGUAGE GADTs #-}
>     
>     data Foo v where
>         Foo :: forall v. Foo (Maybe v)
>     
>     -- Works
>     foo1 :: Foo a -> a -> Int
>     foo1 Foo Nothing  = undefined
>     foo1 Foo (Just x) = undefined
>     
>     -- This works
>     foo2 :: a -> Foo a -> Int
>     foo2 x Foo = foo2' x
>     
>     foo2' :: Maybe a -> Int
>     foo2' Nothing = undefined
>     foo2' (Just x) = undefined
>     
>     -- This doesn't!
>     foo3 :: a -> Foo a -> Int
>     foo3 Nothing  Foo  = undefined
>     foo3 (Just x) Foo = undefined
(Continue reading)


Gmane