zipWith, zipWith3, zipWith4.... looks gawky, IMHO
Hi all. I'm new to this mailing list. (and still a relative newbie in Haskell - learning GraphicsLib) Because the Wish List did not work (maybe it is my browsers fault), I now write it to this list. I found the zipWithN functions in the standard libs, but imho it would be much more comfortable to use operators like in this example: zipWith6 :: (a->b->c->d->e->f -> g) -> ([a]->[b]->[c]->[d]->[e]->[f] -> [g]) zipWith6 f as bs cs ds es fs = f :< as >< bs >< cs >< ds >< es >< fs infixl 123whatever (:<), (><) -- lower priority than (++) (:<) :: (a->b) -> [a] -> [b] (:<) = map (><) :: [(a->b)] -> [a] -> [b] (><) = zipWith id or better: (><) :: [(a->b)] -> [a] -> [b] (><) (f:fs) (x:xs) = (f x) : (fs >< xs) (><) _ _ = [] The fibs example would now look like this: take 10 fibs where fibs = 1 : 1 : ( (+) :< fibs >< tail fibs ) instead of take 10 fibs where fibs = 1 : 1 : zipWith (+) (fibs) (tail fibs) What does you suggest/what's your oppinion to this? (maybe other operators?) - Marc
On Sun, Aug 18, 2002 at 06:32:27PM +0200, Coeus@gmx.de wrote:
Hi all. I'm new to this mailing list. (and still a relative newbie in Haskell - learning GraphicsLib) Because the Wish List did not work (maybe it is my browsers fault), I now write it to this list.
I found the zipWithN functions in the standard libs, but imho it would be much more comfortable to use operators like in this example:
... infixl 123whatever (:<), (><) -- lower priority than (++)
(:<) :: (a->b) -> [a] -> [b] (:<) = map
(><) :: [(a->b)] -> [a] -> [b] (><) = zipWith id
Nice, except that operator names that start with ':' are constructors. Have you seen the paper "Do we need dependent types" <http://www.brics.dk/RS/01/10/>? They do the same trick, and go further. --Dylan
Nice, except that operator names that start with ':' are constructors.
Have you seen the paper "Do we need dependent types" <http://www.brics.dk/RS/01/10/>? They do the same trick, and go further.
--Dylan
No; but now I have it. I do not know where to use zipWith8 instead of operators. - Marc P.S.: AddOn (:<) :: (a->b) -> [a] -> [b] (:<) :: map (><) :: [(a->b)] -> [a] -> [b] (><) (f:fs) (a:as) = f a : ( fs >< as ) (><) _ _ = [] (><*) :: [(a->b)] -> a -> [b] (><*) (f:fs) a = f a : ( fs >: a ) (><*) _ _ = [] to use it in sth like... concat $ ("("++) :< map ((++).show) is ><* ("|"++) >< map ((++).show) js ><* "\n" (I did not test it)
participants (2)
-
Coeus@gmx.de -
Dylan Thurston