[Haskell-cafe] Re: Problems interpreting
Andrea Rossato
mailing_list at istitutocolli.org
Mon Sep 18 16:53:50 EDT 2006
On Mon, Sep 18, 2006 at 11:04:27AM -0400, Lennart Augustsson wrote:
> 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] ]
This is the version I first wanted to (try to) implement (improvements
thanks to the thread, obviously :-):
newtype SF a b = SF { runSF :: [a] -> [b] }
instance Arrow SF where
arr f = SF (map f)
SF f >>> SF g = SF (f >>> g)
first (SF f) = SF (unzip >>> first f >>> uncurry zip)
substitute e l = arr (\x->if x==e then l else [x]) >>> SF concat
I was studying Hughes when I read the first mail of this thread. But
you can see it yourself...
Andrea
More information about the Haskell-Cafe
mailing list