Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Infix operator and precedence (Patrick LeBoutillier)
2. Re: Infix operator and precedence (Isaac Dupree)
3. Re: Infix operator and precedence (Chadda? Fouch?)
----------------------------------------------------------------------
Message: 1
Date: Fri, 24 Dec 2010 10:32:30 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] Infix operator and precedence
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I'm just messing around with infix operators, and I'm trying to
implement some kind of ternary if operator:
(??) :: Bool -> (Bool -> a) -> a
(??) = flip ($)
(?:) :: a -> a -> (Bool -> a)
t ?: f = \b -> if b then t else f
test b = b ?? ("IF" ?: "THEN")
I would like to get rid of the parentheses around the ("IF" ?: "THEN")
part, but I'm not familiar with the
use of theinfixr/infixl functions. I'm not sure which one to use in
this case and how exactly to use it.
Can anyone shed some light?
Thanks a lot,
Patrick
--
=====================
Patrick LeBoutillier
Rosem?re, Qu?bec, Canada
------------------------------
Message: 2
Date: Fri, 24 Dec 2010 11:46:15 -0500
From: Isaac Dupree <[email protected]>
Subject: Re: [Haskell-beginners] Infix operator and precedence
To: Patrick LeBoutillier <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 12/24/10 10:32, Patrick LeBoutillier wrote:
> test b = b ?? ("IF" ?: "THEN")
This is right-associative. This binds more tightly in the ?:. Either is
sufficent to make your infix work:
infixr 1 ??
infixr 1 ?:
or
infix 1 ??
infix 2 ?:
(I picked low numbers 1 and 2 arbitrarily and because C's ?: operator is
also rather low precedence. See what happens if you do + and * inside
your ternary-if if you use infix numbers like 8 or 9.)
------------------------------
Message: 3
Date: Fri, 24 Dec 2010 18:51:03 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] Infix operator and precedence
To: Patrick LeBoutillier <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Fri, Dec 24, 2010 at 4:32 PM, Patrick LeBoutillier
<[email protected]> wrote:
> Hi,
>
> I'm just messing around with infix operators, and I'm trying to
> implement some kind of ternary if operator:
>
> (??) :: Bool -> (Bool -> a) -> a
> (??) = flip ($)
>
> (?:) :: a -> a -> (Bool -> a)
> t ?: f = \b -> if b then t else f
>
> test b = b ?? ("IF" ?: "THEN")
>
> I would like to get rid of the parentheses around the ("IF" ?: "THEN")
> part, but I'm not familiar with the
> use of theinfixr/infixl functions. I'm not sure which one to use in
> this case and how exactly to use it.
There's also the possibility to do the following :
(True ?? t) f = t
(False ?? t) f = f
Then you can do things like that :
> False ?? "Hello"
> $ False ?? "Goodbye"
> $ "Adios"
"Adios"
You can even define (?:) as ($) if you want your own operators.
--
Jeda?
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 30, Issue 43
*****************************************