I’m Brent Yorgey. I am an assistant professor in the department of mathematics and computer science at Hendrix College in Conway, Arkansas, USA. My academic/professional interests include functional programming languages (especially Haskell), type systems, category theory, combinatorics, discrete mathematics in general, and computer science and mathematics education. Other interests include music (I am a classical and jazz pianist), Go, bridge, and classical Greek and Hebrew.
Advertisements
Hi
I’ve been reading your site for a while now, and it’s very interesting. Great job! you may know the answer to a question that I have been wondering about recently, but cant find the answer. Is it possible (I know Haskell doesnt seem to provide a list subtraction operator) to express a statement of infinite lists like:
[1..] – [2..]
Whichshould yield “1” as the answer?
Hi Rory,
Haskell does actually provide a list difference operator, it’s called (\\), and can be found in Data.List. For example, [1,2,3,4] \\ [2,3,5] evaluates to [1,4], and [2,2,3] \\ [2,1] evaluates to [2,3]. However, if you try typing [1..] \\ [2..] at the ghci prompt it will sit there forever trying to compute the first value of the result. (\\) can’t deal with infinite lists, since list difference cannot work for infinite lists in general. There’s no way for \\ to know that the lists you gave it happen to have this special structure.
With that said, it should be quite easy to define a new data type which can store this special structure, and a list difference operator (and other operators) which can take advantage of it. For example, something like
data NewList a = Normal [a] | Infinite a | Range a a
Then you could define
listDiff :: (Eq a, Succ a) => NewList a -> NewList a -> NewList a
such that listDiff (Infinite 1) (Infinite 2) evaluated to (Range 1 1) or something like that.
Let me also take this opportunity to point out that the #haskell IRC channel on freenode.net is a fun place full of helpful people (strange, I know!) and you might enjoy hanging out there and asking any more questions you might have.
Pingback: Differences and Intersections on Infinite Lists. « tech guy in midtown
Brent,
I was surprised to stumble on this post because I’ve been thinking this problem recently. I wrote up my thoughts last night and posted them here:
http://techguyinmidtown.com/2008/04/30/differences-and-intersections-on-infinite-lists/
harfga: Cool, thanks for letting me know! I posted a comment over there with another idea that you might find interesting.
Great blog title. I’ve been studying Haskell lately. It seems there are a fair number of J programmers that find this language interesting. So far so good. I rather like Haskell’s take on outer products and uniform treatment of currying.
Hmm, I’m not 100% sure I know what you mean by “Haskell’s take on outer products” — are you talking about list comprehensions? In any case, I’m glad you’re finding it interesting! Haskell certainly does make a lot of interesting decisions that are quite different from most mainstream languages.
Very nice blog. I’m looking forward to reading through some of the archives. I’ll be posting some category theoretical posts on my blog in the near future. I’m looking at implementing category theoretic constructions in ML as I go through the mathematical background. Perhaps you might enjoy it :)
Sounds cool, I’ve just subscribed to your RSS feed! Actually I think I remember seeing a link to some other post on your blog once before but I forget which one.
I really like the title of your blog, it was so funny at first. :)
Hi Brent, I think you may be the one who designed this Haskell site: http://www.cis.upenn.edu/~cis194/spring13/lectures/01-intro.html
Just wanted to let you know that, reading this one a Firefox browser, the ‘>’ symbol meant to denote code doesn’t show up on code. Or perhaps it’s not meant to be there in the page, just in the downloadable code?
Yeah, it’s only supposed to show up in the downloadable code. You can argue about whether that was a good choice, but that is how I designed it. =)