
7 Jul
2010
7 Jul
'10
5:15 a.m.
On Wed, Jul 07, 2010 at 08:26:50AM +0100, Stephen Tetley wrote:
Hi Michael
Untested - maybe you can use Record puns (section 7.3.15.of the GHC manual). Though they might only work if you have used field names in your data type.
{} swaps for _ _ _ _ _ _ so it would be:
doSomething :: Maybe Result doSomething item = case item of note@(Note {}) -> Just $ process note _ -> Nothing
Nope, this works in general, whether you've used field names or not. I use this trick all the time. Also, I see no reason to use a case; why not just doSomething item@(Note{}) = Just $ process item doSomething _ = Nothing -Brent