
Stuart A. Kurtz schreef op 10-5-2014 18:02:
Dear Roelof,
Thanks , it's working now like this :
loop :: Int -> IO () loop n = do if n <= 100 then do putStrLn (show n ); putChar ' '; putStrLn (show (n * n )) ; loop (n + 1); else return () ;
main :: IO () main = loop 1
But the outcome looks like this:
1 1 2 4 You're getting good advice, but this strikes me as extraordinarily unidiomatic Haskell -- it reads like a translated C program. Fixing it doesn't eliminate that sense.
Why not this?
main :: IO () main = putStr . unlines . map (unwords . map show . (\n -> [n,n^2])) $ [1..100]
Peace,
Stu
Like I said to another person . Im now following this course: https://www.fpcomplete.com/school/starting-with-haskell/basics-of-haskell But I get the feeling it's not a good one. Maybe find another tutorial/course where I can learn it the right way and do a lot of exercises so I can see if I understand things right. I learn the best by doing things and not only read about it. Roelof

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Roelof, Have you considered reading LYAH[0]? It is very good, and you can make up your own exercises if there aren't enough of them for you. :-) [0] http://learnyouahaskell.com/ P.S.
main = putStr . unlines . map (unwords . map show . (\n -> [n,n^2])) $ [1..100] While we're having fun golfing, my attempt:
mapM_ (\(x, y) -> printf "%d %d\n" x y) $ [(n, n^2) | n <- [1..100]] - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNuU2AACgkQRtClrXBQc7WzawEAt4TWloH3QhvC6vvHn4Xx2FAB jwwsGzhe7GR/gKYcikcA/2tR1IlDVIIERjk2AnRccuGIqmNQZeT7ODdwuiw3mbCk =WO8R -----END PGP SIGNATURE-----

Alexander Berntsen schreef op 10-5-2014 18:27:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
Roelof,
Have you considered reading LYAH[0]? It is very good, and you can make up your own exercises if there aren't enough of them for you. :-)
yes, but I never find exercises there where I must do something. I find a lot of examples but maybe I missed them. Roelof

You could try https://github.com/NICTA/course which is *all* exercises!
On 10 May 2014 18:37, Roelof Wobben
Alexander Berntsen schreef op 10-5-2014 18:27:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
Roelof,
Have you considered reading LYAH[0]? It is very good, and you can make up your own exercises if there aren't enough of them for you. :-)
yes, but I never find exercises there where I must do something. I find a lot of examples but maybe I missed them.
Roelof
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ian Ross Tel: +43(0)6804451378 ian@skybluetrades.net www.skybluetrades.net

Additionally, there's http://www.seas.upenn.edu/~cis194/lectures.html
Also a number of other resources for beginners are listed here:
https://gist.github.com/bitemyapp/8739525
On Sat, May 10, 2014 at 11:41 AM, Ian Ross
You could try https://github.com/NICTA/course which is *all* exercises!
On 10 May 2014 18:37, Roelof Wobben
wrote: Alexander Berntsen schreef op 10-5-2014 18:27:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
Roelof,
Have you considered reading LYAH[0]? It is very good, and you can make up your own exercises if there aren't enough of them for you. :-)
yes, but I never find exercises there where I must do something. I find a lot of examples but maybe I missed them.
Roelof
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ian Ross Tel: +43(0)6804451378 ian@skybluetrades.net www.skybluetrades.net
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sat, May 10, 2014 at 12:26 PM, Sam Caldwell
Additionally, there's http://www.seas.upenn.edu/~cis194/lectures.html
That (or possibly an earlier version) is also available on the School of Haskell (with interactive code) at https://www.fpcomplete.com/school/starting-with-haskell/introduction-to-hask...

On Sat, May 10, 2014 at 11:41 AM, Ian Ross
You could try https://github.com/NICTA/course which is *all* exercises!
If you just want exercises, try doing some of the problems at Project Euler https://projecteuler.net/problems. These are pretty heavy on the math, though.

Dear Alexander,
While we're having fun golfing, my attempt:
mapM_ (\(x, y) -> printf "%d %d\n" x y) $ [(n, n^2) | n <- [1..100]]
Nice, although I'm a bit perplexed as to why it typechecks without hints, whereas the following (which avoids the boxing/unboxing of pairs) does not: mapM_ (\n -> printf "%d %d" n (n^2)) [1..100] Peace, Stu

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 10/05/14 19:45, Stuart A. Kurtz wrote:
Nice, although I'm a bit perplexed as to why it typechecks without hints, whereas the following (which avoids the boxing/unboxing of pairs) does not:
mapM_ (\n -> printf "%d %d" n (n^2)) [1..100] This type checks and works fine in GHCi.
? :t mapM_ (\n -> printf "%d %d" n (n^2)) [1..100] mapM_ (\n -> printf "%d %d" n (n^2)) [1..100] :: (Monad m, PrintfType (m b)) => m ( ? mapM_ (\n -> printf "%d %d" n (n^2)) [1..100] 1 12 43 94 165 256 367 498 649 8110 10011 12112 14413 16914 19615 22516 25617 28918 32419 36120 40021 44122 48423 52924 57625 62526 67627 72928 78429 84130 90031 96132 102433 108934 115635 122536 129637 136938 144439 152140 160041 168142 176443 184944 193645 202546 211647 220948 230449 240150 250051 260152 270453 280954 291655 302556 313657 324958 336459 348160 360061 372162 384463 396964 409665 422566 435667 448968 462469 476170 490071 504172 518473 532974 547675 562576 577677 592978 608479 624180 640081 656182 672483 688984 705685 722586 739687 756988 774489 792190 810091 828192 846493 864994 883695 902596 921697 940998 960499 9801100 10000 But if I chuck it in a source file and attempt to runhaskell or compile it, this fails with a very nasty error. Oh, what fun! To make it work ni a source file, you need a type signature in there somewhere. E.g.: main = mapM_ (\n -> printf "%d %d" (n :: Int) (n^2)) [1..100] This works fine. This is indeed interesting! Someone care to additionally make it enlightening as well? - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNuZrUACgkQRtClrXBQc7U7+wD/QKhDvJawLyzziks+QZ2ypVQz qSglFRu+TCsNXQJqrVsA/jmS8x3xit3lypPX3y3Lmctl9tgudSLsPxccba5qcYXd =CiiY -----END PGP SIGNATURE-----

On Sat, May 10, 2014 at 1:49 PM, Alexander Berntsen
But if I chuck it in a source file and attempt to runhaskell or compile it, this fails with a very nasty error. Oh, what fun! To make it work ni a source file, you need a type signature in there somewhere. E.g.:
main = mapM_ (\n -> printf "%d %d" (n :: Int) (n^2)) [1..100]
This works fine. This is indeed interesting! Someone care to additionally make it enlightening as well?
http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluati... -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 10/05/14 19:59, Brandon Allbery wrote:
http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluati... Very
cool. Thanks for the link. - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNvezQACgkQRtClrXBQc7UEdgD+JopCmOmLU3Ajp4lMAQJv3g3b 3RRi2WzHIyAQnvYTJsgA/38yDsqUSOOvR10fKlsk41+w2nL3Mt9oKsCh523DKIQP =NYMz -----END PGP SIGNATURE-----

Dear Alexander,
On May 10, 2014, at 12:49 PM, Alexander Berntsen
? mapM_ (\n -> printf "%d %d" n (n^2)) [1..100] 1 12 43 94 165 256 367 498 649 8110 10011 12112 14413 16914 19615 22516 25617 28918 32419 36120 40021 44122 48423 52924 57625 62526 67627 72928 78429 84130 90031 96132 102433 108934 115635 122536 129637 136938 144439 152140 160041 168142 176443 184944 193645 202546 211647 220948 230449 240150 250051 260152 270453 280954 291655 302556 313657 324958 336459 348160 360061 372162 384463 396964 409665 422566 435667 448968 462469 476170 490071 504172 518473 532974 547675 562576 577677 592978 608479 624180 640081 656182 672483 688984 705685 722586 739687 756988 774489 792190 810091 828192 846493 864994 883695 902596 921697 940998 960499 9801100 10000
Yeah, it is better with the \n ;-). Peace, Stu
participants (7)
-
Alexander Berntsen
-
Brandon Allbery
-
Ian Ross
-
Mike Meyer
-
Roelof Wobben
-
Sam Caldwell
-
Stuart A. Kurtz