[Haskell-cafe] Re: Problems interpreting

Lennart Augustsson lennart at augustsson.net
Mon Sep 18 11:04:27 EDT 2006


Or even shorter:

subst e l = concatMap $ \x->if x==e then l else [x]

I kinda like the list comprehension version too

subst e l1 l2 = [ r | x <- l2, r <- if x==e then l1 else [x] ]


On Sep 18, 2006, at 10:54 , Jón Fairbairn wrote:

> Andrea Rossato <mailing_list at istitutocolli.org> writes:
>
>> On Mon, Sep 18, 2006 at 12:42:59PM +0100, Jón Fairbairn wrote:
>>> And if you do that, you can write it like this:
>>>
>>>    subst e l'
>>>        = concat . map subst_elem
>>>          where subst_elem x
>>>                    | x == e = l'
>>>                    | otherwise = [x]
>>
>> Pretty. Just to many keystrokes.
>
> Keystrokes? Learn to touchtype!
>
>> This should take two keystrokes less, probably:
>>
>> subst e l [] = []
>> subst e l (x:xs) = if x == e then l ++ xs else x : subst e l xs
>
> but if you want short, do this:
>
>> subst e l' = concat.map (\x->if x==e then l' else [x])
>
> which beats yours by twenty seven characters and one bug ;-P
>
> --  
> Jón Fairbairn                                  
> Jon.Fairbairn at cl.cam.ac.uk
> http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated  
> 2006-09-13)
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list