[Haskell-cafe] Point-free style in guards
Evan Laforge
qdunkan at gmail.com
Tue Jul 22 13:33:54 EDT 2008
On Tue, Jul 22, 2008 at 10:27 AM, Neil Mitchell <ndmitchell at gmail.com> wrote:
> Hi
>
>> Why such a style doesn't work, so I must write ugly code like that:
>>
>> outStanza a | (isMessage a) = outMessage a
>> | (isPresence a) = outPresence a
>> | (isIQ a) = outIQ a
>
> You can make it slightly prettier, since the brackets are not necessary:
>
> outStanza a | isMessage a = outMessage a
> | isPresence a = outPresence a
> | isIQ a = outIQ a
Also, if it really is in that format, maybe you can write something like:
switch v pairs = maybe (error "no match") ($v) (lookupWith ($v) pairs)
And then you can write the list point-free, though you don't get the
nice guard syntax. I guess lookupWith must be one of my local
functions, but it's easy to write too.
More information about the Haskell-Cafe
mailing list