[Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-23 Thread apfelmus
Mirko Rahn wrote: apfelmus wrote: Note that using Peano-numbers can achieve the same effect of stopping the length calculation as soon as more than one character is different. data Nat = Zero | Succ Nat deriving (Eq, Ord) instance Num Nat where (Succ x) + y = Succ (x+y)

Re: [Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-22 Thread Mirko Rahn
apfelmus wrote: Note that using Peano-numbers can achieve the same effect of stopping the length calculation as soon as more than one character is different. data Nat = Zero | Succ Nat deriving (Eq, Ord) instance Num Nat where (Succ x) + y = Succ (x+y) Zero+ y = y Very

Re: [Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-20 Thread Paul Johnson
Dougal Stanton wrote: I think I will have to, sooner or later, become more versed in the subtle ways of non-IO monads. They seem to be capable of some seriously tricksy shenanigans. Keep trying. At some point you will achieve enlightenment in a blinding flash of light. Then you will write a

[Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-19 Thread apfelmus
Dougal Stanton wrote: I worked out that [ (a,b) | a - as, b - bs ] must be equivalent to comp = concatMap (\x - map ((,) x) ys) xs but I can't really say how conditions like a /= b get slotted in to that style. Is there a reference for that? Here's an example translation [ (a,b) | a -

[Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-19 Thread apfelmus
Mirko Rahn wrote: wanted ws = [ (w,v) | (w:vs) - tails ws, v - vs, difference w v 2 ] Moreover, we only calculate the difference to check whether it is smaller than 2. We can do this directly (capturing the common pattern): diff_lt_2 = diff (diff (const . const $ False)) diff _ []

[Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-18 Thread apfelmus
Dougal Stanton wrote: The following is a slap-dash program for generating a list of pairs of words which differ by, at most, one letter. It's quite verbose at the moment, because (a) that was the way I wrote it, a snippet at a time, and (b) I lack the wit to make it shorter. Can anyone

Re: [Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-18 Thread Dougal Stanton
On 18/07/07, apfelmus [EMAIL PROTECTED] wrote: I like it for its elegant point-free style :) Yes, well, I am rather enamoured of them! :-) Apparently, difference can only detect character replacements but not character insertion or deletion, but that's probably not your use case. Yes,

Re: [Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-18 Thread J. Garrett Morris
On 7/18/07, Dougal Stanton [EMAIL PROTECTED] wrote: I worked out that [ (a,b) | a - as, b - bs ] must be equivalent to comp = concatMap (\x - map ((,) x) ys) xs but I can't really say how conditions like a /= b get slotted in to that style. Is there a reference for that? As I understand it,

Re: [Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code cleanup request)

2007-07-18 Thread Dougal Stanton
On 18/07/07, J. Garrett Morris [EMAIL PROTECTED] wrote: You're partway there - concatMap is flip (=), so you have the xs = (\x - stuff) part. Ah, yes! I read about this equivalence in one of the other threads today but it didn't make any connection. Doh! I think I will have to, sooner or