At 2010-10-03T22:45:30+02:00, Dominique Devriese wrote: > You need a function like the following for that: > > comma :: (a -> b) -> (a -> c) -> a -> (b,c) > comma f g x = (f x, g x) > > Then you could say: > > blowup = (uncurry (++)) . comma (blowup . allButLast) lastToTheLength > > Ignore this if you haven't read about Applicative or type classes yet, > but using the Applicative instance for arrow types (->) a, you can > also write > > comma = liftA2 (,) > > or > > blowup = (uncurry (++)) . liftA2 (,) (blowup . allButLast) lastToTheLength
I tried both of them, but they don't seem to work: -- Pointfree blowup. blowup1 :: String -> String blowup1 = (uncurry (++)) . comma1 (blowup1 . allButLast) lastToTheLength comma1 :: (a -> b) -> (a -> c) -> a -> (b,c) comma1 f g x = (f x, g x) blowup2 :: String -> String blowup2 = (uncurry (++)) . comma2 (blowup2 . allButLast) lastToTheLength -- Imported Control.Applicative earlier. comma2 :: (a -> b) -> (a -> c) -> a -> (b,c) comma2 = liftA2 (,) % ghci GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Prelude> :l Chapter01.hs [1 of 1] Compiling Chapter01 ( Chapter01.hs, interpreted ) Ok, modules loaded: Chapter01. *Chapter01> comma1 allButLast lastToTheLength "abcd" ("abc","dddd") *Chapter01> comma2 allButLast lastToTheLength "abcd" ("abc","dddd") *Chapter01> blowup1 "abcd" "^CInterrupted. *Chapter01> blowup2 "abcd" "^CInterrupted. It looks like both the above versions of blowup go into some infinite recursion, and have to be interrupted. Regards, Raghavendra. -- N. Raghavendra <ra...@mri.ernet.in> | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe