You need to use a view pattern with an explicitly bidirectional pattern synonym:
pattern P :: (Int,Int) -> Foo
pattern P xy <- ((\(Foo x y) -> (x, y)) -> xy)
where
P (x, y) = Foo x y
If the Foo type had more than one constructor, then you'd need to do something a bit trickier, like
pattern P xy <- ((\case
Foo x y -> Just (x, y)
_ -> Nothing) -> Just xy)
where
P (x, y) = Foo x y
Hi,
I have a question about PatternSynonyms. Suppose we have:
data Foo = Foo Int Int
I would like to define a pattern as follows:
pattern P :: (Int,Int) -> Foo
pattern P (x,y) = Foo x y
But this results in "parse error on input ‘(’". Are there any ways to
use tuple in the left side hand of patterns?
This is important to maintain backward compatibility for the "network"
library.
If there is no way, I will define Foo as:
data Foo = Foo (Int,Int) -- awkward
and define P as:
pattern P :: (Int,Int) -> Foo
pattern P xy = Foo xy
Regards,
--Kazu
_______________________________________________
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. lol