Excellent bikeshedding opportunity! Frontend syntax for pattern synonym types
Dr. ERDI Gergo
gergo at erdi.hu
Mon Dec 23 03:56:40 UTC 2013
On Sun, 22 Dec 2013, Dr. ERDI Gergo wrote:
>> If it's only A and B, perhaps abominations like these could be considered:
>>
>> -- implicit foralls
>> pattern Show t => P t :: (Num t, Eq b) => b -> T t
>>
>> -- explicit foralls
>> pattern forall t. Show t => P t :: forall b. (Num t, Eq b) => b -> T t
>
> I'm not 100% sure what that 't' in 'P t' is supposed to be in your example.
> 'P' is not like a type constructor at all; it's a lot more like a data
> constructor.
Thinking further about it, I think this could work, using a syntax similar
to data constructor definitions instead of sticking to the function type
syntax:
pattern (Num a, Eq b) => P a b :: (Show a) => T a
or with explicit foralls (using the fact that we can deduce which tyvars
are universial vs existential simply by seeing if they occur in 'T a'):
pattern forall a b. (Num a, Eq b) => P a b :: (Show a) => T a
my only concern with this one is that the direction of the first double
arrow doesn't "feel right".
Other examples with this syntax:
-- Number literal patterns
pattern Z :: (Num a, Eq a) => a
pattern Z = 0
-- Monomorphic patterns
pattern TrueAnd Bool :: [Bool]
pattern TrueAnd b = [True, b]
-- Infix notation
pattern a :< Seq a :: Seq a
pattern x :< xs <- (Seq.viewl -> x Seq.:< xs)
I'm liking this so far.
Bye,
Gergo
--
.--= ULLA! =-----------------.
\ http://gergo.erdi.hu \
`---= gergo at erdi.hu =-------'
RICE: Race Inspired Cosmetic Enhancement
More information about the Glasgow-haskell-users
mailing list