Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org 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 <patrick.leboutill...@gmail.com> Subject: [Haskell-beginners] Infix operator and precedence To: beginners <beginners@haskell.org> Message-ID: <aanlkti=9tfjsa4l2uodc6ca0=+1033so6-ll2bsn3...@mail.gmail.com> 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 <m...@isaac.cedarswampstudios.org> Subject: Re: [Haskell-beginners] Infix operator and precedence To: Patrick LeBoutillier <patrick.leboutill...@gmail.com> Cc: beginners <beginners@haskell.org> Message-ID: <4d14ce57.1000...@isaac.cedarswampstudios.org> 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? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] Infix operator and precedence To: Patrick LeBoutillier <patrick.leboutill...@gmail.com> Cc: beginners <beginners@haskell.org> Message-ID: <aanlktingwp=ag+pdyp6usv3rckv2=fad3g73n-b_z...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Fri, Dec 24, 2010 at 4:32 PM, Patrick LeBoutillier <patrick.leboutill...@gmail.com> 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 Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 30, Issue 43 *****************************************