[Haskell-cafe] Infix tuple comma query (,)
Alexander Dunlap
alexander.dunlap at gmail.com
Mon Apr 6 23:39:20 EDT 2009
On Mon, Apr 6, 2009 at 8:53 AM, Paul Keir <pkeir at dcs.gla.ac.uk> wrote:
> module Main where
>
>
>
> data (:%^&) a b = a :%^& b deriving (Show)
>
>
>
> main = do
>
> print $ 18 :%^& (Just 99)
>
> print $ (,) 9 10
>
> print $ 9 , 10
>
>
>
> The last line in the code above causes a compile error.
>
> Why does infix use of the comma (tuple constructor?) function fail without
> brackets?
>
>
>
> Thanks,
>
> Paul
>
When I want a lighter syntax for pairs (when doing a long list of
them, e.g.), I often define
(&) :: a -> b -> (a,b)
a & b = (a,b)
and then you can indeed write
print $ 1 & 2
(assuming you get precedence right).
Alex
More information about the Haskell-Cafe
mailing list