[Haskell-beginners] Ranges and List Comprehensions in SQL

Brent Yorgey byorgey at seas.upenn.edu
Thu Sep 2 17:52:32 EDT 2010

On Thu, Sep 02, 2010 at 03:54:12PM -0400, Tom Murphy wrote:
> Hi Everyone,
>      Is there a "From SQL"-type function that "restores" a range or list
> comprehension?
> Example:
> Let's say I want to keep track of which episodes of a TV show I've seen. I
> have an SQL table, in which is a record:
>    id (INTEGER): 30
>    title (VARCHAR): "The Simpsons"
>    episodes_watched (Some data format): [1..4], [14], [18..21], [23..25]
> Then, when I pull the record, in Haskell, the "Episodes Watched" is already
> one list:
> [1,2,3,4,14,18,19,21,23,24,25]
> , or a series of lists that I can append together:
> [1,2,3,4], [14], [18,19,20,21], [23,24,25]
> Note in the example that I would like to be able to store multiple ranges
> within a single record.

I am not sure I understand what you are asking.  Do you want something
like this?

  data Range = Range Integer Integer

  toRanges :: [Integer] -> [Range]
  toRanges = ...

toRanges should not be too hard to write but nothing like that exists
as far as I know.

But I'm pretty sure I haven't understood your question, because I
don't see what SQL has to do with it.  Are you actually using a
database?  Or are you just using SQL as inspiration?


More information about the Beginners mailing list