[Haskell-cafe] unary pattern matching

Brian Hulley brianh at metamilk.com
Fri Jan 27 04:34:40 EST 2006


John Meacham wrote:
> On Fri, Jan 27, 2006 at 12:28:23PM +1100, Donald Bruce Stewart wrote:
>> john:
>>> I have often wanted a shorthand syntax for testing if a value
>>> matches a given pattern. I want to implement such an extension for
>>> jhc but can't decide an appropriate syntax so I thought I'd ask the
>>> group. basically I want something like
>>>
>>> /Left (Just _)/   expands to
>>>
>>> \x -> case x of
>>>         Left (Just _) -> True
>>>         _ -> False
>>
>> Something like pattern guards?
>>
>>     f x | Just _ <- x = putStrLn "something"
>
> hmm.. how about
>
> (| Left (Just _) |)
>
> since | cannot be used as a section so it can be unambigously lexed
> as a different symbol. I think I like it. any other ideas?
>
>         John

(@ Left (Just _) @) would fit in with the use of @ in as-patterns
Also, the as-pattern syntax could be stolen for expressions so that exp at pat 
would evaluate to True or False when this syntactic form appears in an 
expression instead of a pattern ie to give the following equivalence:

         (@ pat @) exp        ===           exp @ pat

Regards, Brian. 



More information about the Haskell-Cafe mailing list