Paste: Le compte est bon
Author: | Jon |
Mode: | literate-haskell |
Date: | Sat, 20 Jun 2009 16:53:14 |
Plain Text |
> import List
> f x = [ delete (a,str1) (delete (b,str2) ((a+b,"("++str1++"+"++str2++")"):x)) | (a,str1) <- x, (b,str2) <-x, not ((a,str1) == (b,str2))] ++
> [ delete (a,str1) (delete (b,str2) ((a-b,"("++str1++"-"++str2++")"):x)) | (a,str1) <- x, (b,str2) <-x, not ((a,str1) == (b,str2))] ++
> [ delete (a,str1) (delete (b,str2) ((a*b,"("++str1++"*"++str2++")"):x)) | (a,str1) <- x, (b,str2) <-x, not ((a,str1) == (b,str2))] ++
> [ delete (a,str1) (delete (b,str2) ((a/b,"("++str1++"/"++str2++")"):x)) | (a,str1) <- x, (b,str2) <-x, not ((a,str1) == (b,str2))]
> member x [] = Nothing
> member x ((y,expr):ys) | x == y = Just (y,expr)
> | otherwise = member x ys
> member2 x [] = Nothing
> member2 x (list:lists) = case (member x list) of
> Nothing -> member2 x lists
> Just a -> Just a
> myfind a lists = case (member2 a lists) of
> Just a -> do
> putStrLn "Trouvé : "
> putStrLn (show a)
> Nothing -> do
> putStrLn "j'itère .."
> myfind a ( lists >>= f )
New Annotation