Google Groups Home
Help | Sign in
Or-Patterns in Haskell yet?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Phil Tomson  
View profile
 More options May 9, 7:13 pm
From: "Phil Tomson" <philtom...@gmail.com>
Date: Fri, 9 May 2008 16:13:07 -0700
Local: Fri, May 9 2008 7:13 pm
Subject: Or-Patterns in Haskell yet?
I was reading through Okasaki's paper "Red-Black Trees in a Functional
Setting" (recommended ) today and translating the code from Haskell to
OCaml as I went along.

I noticed that when he got to the balance function he says something
to the effect of "If Haskell had or-patterns this is how you could
write this function more concisely".  I noticed that this paper was
written in '93 so I figured that maybe Haskell has Or-patterns now,
but a google search didn't uncover anything conclusive - there was
some 2005 post by Simon Peyton-Jones saying that he'd add them if
anyone came up with an implementation.  So has anyone come up with an
implementation?

This is how the balance function came out in OCaml:

  let rec balance t = match t with
     T(B, T(R, T(R, a,x,b), y, c), z, d) | T( B, T(R,a,x,T(R,b,y,c)),z,d) |
     T(B,a,x, T(R,T(R,b,y,c),z,d) )      | T(B,a,x,T(R,b,y,T(R,c,z,d))) ->
        T(R, T(B,a,x,b), y, T(B, c,z,d))
   | _ -> t ;;

Phil


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iavor Diatchki  
View profile
 More options May 9, 8:51 pm
From: "Iavor Diatchki" <iavor.diatc...@gmail.com>
Date: Fri, 9 May 2008 17:51:03 -0700
Local: Fri, May 9 2008 8:51 pm
Subject: Re: [pdxfunc] Or-Patterns in Haskell yet?
Hello,
Indeed, there are no or-patterns in Haskell.  They are not hard to
implement but I don't think that there has been much demand for them
(and Haskell is a rather large language already :-).  By the way, you
should send this email to one of the Haskell lists
(haskell-c...@haskell.org seems appropriate).  Your example is quite
nice, and it may turn out that other people would find such
functionality useful too.
-Iavor


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google