[Haskell-cafe] point-free ADT pattern matching ?

Alexey Karakulov ankarakulov at gmail.com
Thu Jul 15 16:58:36 EDT 2010

I wonder if pattern matching could be less verbose. Maybe this sounds weird,
but here is example of what I mean:

> type A = (Int, String)
> f :: String -> A -> A
> f s (i,s') = (i, s ++ s')
> data B = B Int String deriving Show
>g :: String -> B -> B
>g s (B i s') = B i $ s ++ s'

Types A/B and functions f/g are quite similar: (x :: A) or (x :: B) means
that x contains some integer and string values, and f/g functions take some
string and prepend it to the string part of x. The code for f and g has the
same level of verbosity, but -- ta-dah! -- we can use arrows and define f in
a highly laconic manner:

> import Control.Arrow
> f' :: String -> A -> A
> f' = second . (++)

So my queastion is how I could define (g' :: String -> B -> B) in the same
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100715/030ab857/attachment.html

More information about the Haskell-Cafe mailing list