Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

An EXPERT PROGRAMMER explains OO

Name: Anonymous 2008-03-19 11:50

Because I know you were all having so much trouble with this difficult concept.

http://theunixgeek.blogspot.com/2007/11/understanding-object-oriented.html

Name: Anonymous 2008-03-21 17:03

Prelude> mapM (putStrLn . show) [1..4]
1
2
3
4
[(),(),(),()]

Uhm, where did that list of empty tuples come from?

Name: Anonymous 2008-03-21 17:06

>>32
putStrLn :: String -> IO ()

Name: Anonymous 2008-03-21 17:09

>>33
So I map it along a list of one-element lists and one empty list. That's not a reason to show the last nil as empty tuples.

Name: Anonymous 2008-03-21 18:05

>>32
Nomads.  Haskell nomads.

Name: Anonymous 2008-03-21 18:07

>>34
?
The 1, 2, 3, 4 are printed as a result of calling putStrLn on each element. The [(),(),(),()] is the resulting list from your mapM call.

Name: Anonymous 2008-03-21 18:16

>>36
The [(),(),(),()] is the resulting list from your mapM call.
Huh?

The show part actually transforms the list to a list of strings and a nil at the end, right? Why would it return [(),(),(),()] ?

Name: Anonymous 2008-03-21 18:20

>>37
                  /      \
               {       ヽ
         ____   ハ     }
         ̄`>: : : : : ∨: : ー‐ --yz 、
         /: : : : : : : :/: : : : : : : : : : 、: :\
       /:_: : : : :/: : /: |: : : : : : : : : : :\: : ヽ
      / /// : :/: : :/:/:!: : :.:.|、: : : : : : : \: :.',
.      {/ // : :/: : :/_/:小:. :.:.|_ヽ__: : : : ヽ: l
        l/l : : !: : 7゙/ノ l| V:.|  \: : : :、 : : l: |
         |: :/|: :/:/  j|  ヽ|   \: : \: :!: \_
         |/ |;/l/x≡≡   |≡≡z.ハ: :.ヽl\: : : :\
        r┬z/:.:|           ∠─-ヘトr-く ̄ヽ :\
       r「「l {: : :\    ‐    ////「 { \ヽ:.:\ \ :\
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓

Name: Anonymous 2008-03-21 19:02

>>37
Haskell. Haskell Nomads.

Name: Anonymous 2008-03-21 19:26

>>38
Konachan kawaii

Name: Anonymous 2008-03-21 20:29

>>37
No, the putStrLn . show part transforms the list of numbers to a list of ()'s, printing a bunch of strings as a side effect. The return value is [(),(),(),()]. It's printed because ghci assumes that any non-() value is potentially interesting.
If that's not what you want, make sure that the return value is (), e.g. by using mapM (putStrLn . show) [1..4] >> return (). However, an EXPERT HASKELL PROGRAMMER would use library functions to his advantage and simply write mapM_ print [1..4] or even putStr . unlines . map show $ [1..4].

Name: Simon Peyote Joints 2008-03-21 21:13

>>41
I am a EXPERT HASKELL PROGRAMMER and agree whole-heartedly.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List