#haskell - Sat 28 Apr 2007 between 06:50 and 07:02

NY Lost Funds



gobanhttp://scienceblogs.com/goodmath/2007/04/true_pathology_a_multilingual.php
lambdabotTitle: Good Math, Bad Math : True Pathology: A Multilingual Quine, http://tinyurl.com/23ehx8
maukeprintList [] = return (); printList (hd : tl) = do putStrLn (show hd); printList tl
Calegoban: yeah, that's a nice quine. :)
maukepattern matching!
Calealso, putStrLn . show = print
maukethen you notice that ... what Cale said
then, mapM_
gobanhow the hell they come up with it
Calemauke: right :)
chrizelwhoo, thank you all! now it works... i'm still learning... :)
Calechrizel: printList = mapM_ print
:)
(mapM_ is a function in the Control.Monad library)
You can probably imagine how it might be written :)
_roconnor> let (*.) = "foo" in (*.)
lambdabot"foo"
mauke(sequence_ .) . map
chrizelthanks, that works mapM_ print [1, 2, 3]
maukeputStr (unlines (map show [1, 2, 3]))
Cale:)
mapM and mapM_ is how most loops are handled. There's also (in GHC6.6 and up) forM and forM_, which are the same thing, but with the list parameter first
dolio> 23 `mod` 9
lambdabot5
dolio@check \i -> mod (i :: Integer) 9 == (sum . map digitToInt . show $ i)
lambdabotCouldn't match expected type `Integer' against inferred type `Int'
dolio@check \i -> mod (i :: Int) 9 == (sum . map digitToInt . show $ i)
lambdabotException: Char.digitToInt: not a digit '-'
dolio@check \i -> i > 0 ==> mod (i :: Int) 9 == (sum . map digitToInt . show $ i)
lambdabotFalsifiable, after 20 tests: 9
Cale> sum . map digitToInt . show $ 9
lambdabot9
Cale> mod 9 9
lambdabot0
LeCamarade@src mapM_
lambdabotmapM_ f as = sequence_ (map f as)
Cale@check \i -> i > 0 ==> mod (i :: Int) 9 == mod (sum . map digitToInt . show $ i) 9
lambdabotOK, passed 500 tests.
[malte]Is there a function f, where f = flip map, predefined in any stdlib? (And how could I find out myself?)
mauke@hoogle [a] -> (a -> b) -> [b]

Page: 2 9 16 23 30 37 44 51 58 65 

IrcArchive

NY Lost Funds