[Haskell-cafe] Problems interpreting
Andrea Rossato
mailing_list at istitutocolli.org
Mon Sep 18 07:13:49 EDT 2006
On Mon, Sep 18, 2006 at 12:54:34PM +0200, Albert Crespi wrote:
> Thank you very much for your reply!
> As I said, it is my first experience with Haskell, I have been programming
> in Java and C for some years, and I find this language very different from
> them. Anyway I'll try to fix the function with the information that you gave
> me.
> Thanks again!
>
You're welcome.
By the way, this is what the comments say you are trying to do:
-- Replaces a wildcard in a list with the list given as the third argument
substitute :: Eq a => a -> [a] -> [a] -> [a]
substitute e l1 l2= [c | c <- check_elem l1]
where check_elem [] = l1
check_elem (x:xs) = if x == e then (l2 ++ xs) else check_elem xs
This is the result:
*Main> substitute 1 [1,2,3] []
[2,3]
*Main> substitute 1 [1,2,3] [7,8,9]
[7,8,9,2,3]
*Main>
Have fun with Haskell.
Ciao
Andrea
More information about the Haskell-Cafe
mailing list