Hi all,
I've finished a first draft of what I call "First steps in Haskell". It's intended to be the very first thing a new user sees when they decide to try out Haskell. http://www.haskell.org/hawiki/FirstSteps?action=show It's a bit longer than I'd like, but I don't inmediately see anything I can take out without losing something valuable (given the purpose of this document). Thoughts and comments? Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. / _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
hi daniel, the link about german (deutsch) haskel courses is in fact a
link to a dutch (nederlands) page. For the rest it looks good! Peter > Hi all, > > I've finished a first draft of what I call "First steps in Haskell". > It's intended to be the very first thing a new user sees when they > decide to try out Haskell. > > http://www.haskell.org/hawiki/FirstSteps?action=show > > It's a bit longer than I'd like, but I don't inmediately see anything I > can take out without losing something valuable (given the purpose of > this document). > > Thoughts and comments? > > Cheers, > Daniel. > -- > /\/`) http://oooauthors.org > /\/_/ http://opendocumentfellowship.org > /\/_/ > \/_/ I am not over-weight, I am under-tall. > / > _______________________________________________ > Haskell-Cafe mailing list > [hidden email] > http://www.haskell.org/mailman/listinfo/haskell-cafe > _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
[hidden email] wrote:
> hi daniel, the link about german (deutsch) haskel courses is in fact a > link to a dutch (nederlands) page. > > For the rest it looks good! Thanks. Fixed. I removed the wrong link. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. / _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Daniel Carrera-2
On 12/20/05, Daniel Carrera <[hidden email]> wrote:
> Hi all, > > I've finished a first draft of what I call "First steps in Haskell". > It's intended to be the very first thing a new user sees when they > decide to try out Haskell. > > http://www.haskell.org/hawiki/FirstSteps?action=show > > It's a bit longer than I'd like, but I don't inmediately see anything I > can take out without losing something valuable (given the purpose of > this document). > > Thoughts and comments? It looks very good. The length isn't a problem to me, if anything I'd be happy expanding a little. One thing I'd consider adding is something along the lines of a section: ------------------------------------------------------------------------------------ == So how do I write "Hello, world"? == Well, the first thing you need to understand that in a functional language like Haskell, this is a harder question than it seems. Most of the code you will write in Haskell is "purely functional", which means that it returns the same thing every time it is run, and has no side effects. Code with side effects is referred to as "imperative", and is carefully isolated from functional code in Haskell. To deal with the distinction between functional and imperative code, Haskell uses a construct called the "IO monad". It's not hard to understand - basically, it's just a way of "wrapping up" imperative code so that there's a clear boundary between it and functional code - but most tutorial presentations of Haskell start with functional code, and introduce the IO monad later. As a taster, though, here is "Hello, world" in Haskell: {{{ module Main where main :: IO () main = putStrLn "Hello, World!" }}} Put this in a file called hello.hs, and compile it with `ghc -make hello.hs -o hello`. You'll get an executable called hello (or hello.exe on Windows). Run it to see the output. There will be plenty more on writing standalone programs, IO, and other aspects of the IO monad, as you learn more about Haskell. ------------------------------------------------------------------------------------ The point is, people *will* want to write "hello, world", so don't put them off by making it seem "hard". Show them how, explain where they will find out more, and explain why things like this come naturally at a later stage when learning Haskell than they do with, say, C. Paul. _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Daniel Carrera-2
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Daniel Carrera > > Hi all, > > I've finished a first draft of what I call "First steps in Haskell". > It's intended to be the very first thing a new user sees when they > decide to try out Haskell. > > http://www.haskell.org/hawiki/FirstSteps?action=show > > Thoughts and comments? There's not much wrong with doing a Hello World: main = putStrLn "Hello World" Or: fac n = if n <= 0 then 1 else n * fac (n-1) main = print (fac 12) Compiling, or at least running a haskell script (via runhaskell) should also get a mention, so you show how to achieve things outside of the interactive prompt. Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ***************************************************************** _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Paul Moore-2
> == So how do I write "Hello, world"? ==
> > Well, the first thing you need to understand that in a > functional language like Haskell, this is a harder > question than it seems. Most of the code you will write > in Haskell is "purely functional", which means that it > returns the same thing every time it is run, and has no > side effects. Code with side effects is referred to as > "imperative", and is carefully isolated from functional > code in Haskell. I believe this description is a bit misleading. Code written in the IO monad is purely functional just the same. Haskell knows no other code than purely functional one. In my humble opinion, it's unfortunate that many tutorials and introductionary texts leave the impression that monadic code would be something utterly different than "normal" Haskell code. I feel it intimidates the reader by making a monad appear like black magic, even though it's little more than syntactic sugar to describe implicit function arguments. If we'd have an opaque "World" type instead of the IO monad, 'putStrLn' would be: putStrLn :: String -> World -> World How is this function any different from any other function? So why should putStrLn :: String -> IO () be different from any other function? Peter _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On 20 Dec 2005 19:52:31 +0100, Peter Simons <[hidden email]> wrote:
> > == So how do I write "Hello, world"? == > > > > Well, the first thing you need to understand that in a > > functional language like Haskell, this is a harder > > question than it seems. Most of the code you will write > > in Haskell is "purely functional", which means that it > > returns the same thing every time it is run, and has no > > side effects. Code with side effects is referred to as > > "imperative", and is carefully isolated from functional > > code in Haskell. > > I believe this description is a bit misleading. Code written > in the IO monad is purely functional just the same. Haskell > knows no other code than purely functional one. In my humble > opinion, it's unfortunate that many tutorials and > introductionary texts leave the impression that monadic code > would be something utterly different than "normal" Haskell > code. I feel it intimidates the reader by making a monad > appear like black magic, even though it's little more than > syntactic sugar to describe implicit function arguments. > > If we'd have an opaque "World" type instead of the IO monad, > 'putStrLn' would be: > > putStrLn :: String -> World -> World > > How is this function any different from any other function? > So why should > > putStrLn :: String -> IO () > > be different from any other function? > It's sometimes beneficial to "lie" a bit when starting out. Perhaps say something like "this is a simplified view of things, for all the gory details see chapter 19". Monadic IO is pretty darn cool, sadly that means that many tutorial authors are tempted to spend pages upon pages explaining exactly why it's cool and how it works, but that is NOT what most people starting out with the language need to read. I'm still looking for a good *practical* tutorial that I could recommend to newcomers. IO, data types and QuickCheck in the very first chapter, I say! Real program examples from the get go, and go into the theory on why this has been hard in FP before Haskell (or Monadic IO rather) much much later, so as to not scare people away. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Peter Simons
Peter Simons wrote:
> In my humble > opinion, it's unfortunate that many tutorials and > introductionary texts leave the impression that monadic code > would be something utterly different than "normal" Haskell > code. I feel it intimidates the reader by making a monad > appear like black magic, even though it's little more than > syntactic sugar to describe implicit function arguments. I'm scared of monads :) I really don't know what a monad is. All I know is that you need it for IO because IO implies side-effects and I know that "Monad" is a very scary-looking word :) > If we'd have an opaque "World" type instead of the IO monad, > 'putStrLn' would be: > > putStrLn :: String -> World -> World That seems less scary. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. / _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Daniel Carrera writes:
> I'm scared of monads :) I really don't know what a monad > is. Neither do I, but that doesn't mean that I can't use just fine. ;-) >> putStrLn :: String -> World -> World > > That seems less scary. Things become a lot clearer when you think about how to print _two_ lines with that kind of function. You'd write: f :: World -> World f world = putStrLn "second line" (putStrLn "first line" world) The 'world' parameter forces the two functions into the order you want, because printing "second line" needs the result of printing "first line" before it can be evaluated. However, writing complex applications with that kind of API would drive you nuts, so instead you can say f :: IO () f = do putStrLn "first line" putStrLn "second line" and it means the exact same thing. Curiously enough, if you check out the reference documentation at: http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad-ST.html#t%3ARealWorld ..., you'll find that a "World" type actually exists. Peter _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Sebastian Sylvan
On Tue, 2005-12-20 at 20:07 +0100, Sebastian Sylvan wrote:
. . . > I'm still looking for a good *practical* tutorial that I could > recommend to newcomers. > IO, data types and QuickCheck in the very first chapter, I say! Real > program examples from the get go, and go into the theory on why this > has been hard in FP before Haskell (or Monadic IO rather) much much > later, so as to not scare people away. I second this motion. I've been interested in Haskell for some time, experimented with it several years ago, and then moved on to other things. That first time around I saw no comprehensible discussions of monadic IO (for example, I thought that the fact that when you're in a monad you can't get out was characteristic of monads in general, not a peculiarity of IO). The state of available knowledge for beginners has clearly improved since I last looked. I applaud this discussion for making Haskell more accessible for the newbie. (Now, if someone would just explain how to get reliable performance information while jumping through only a bounded number of hoops ... :-) -- Bill Wood _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Peter Simons
Hi,
> Hugs Interpreter only Suitable for learning. You'll need GHC for serious work. This is putting Hugs down quite a bit. I personally prefer Hugs, and use it for serious work (including developing a Haskell compiler, and 4 years of academic study and counting). About the only thing it doesn't do is produce standalone binaries. I would have actually said Hugs, and especially the Windows front end WinHugs was a lot more suitable for beginners than GHC, but the wiki page very much gives the other impression. Thanks Neil _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Peter Simons
On Tuesday 20 December 2005 20:58, Peter Simons wrote:
> Daniel Carrera writes: > > I'm scared of monads :) I really don't know what a monad > > is. > > Neither do I, but that doesn't mean that I can't use just > fine. ;-) > > >> putStrLn :: String -> World -> World > > > > That seems less scary. > > Things become a lot clearer when you think about how to > print _two_ lines with that kind of function. You'd write: > > f :: World -> World > f world = putStrLn "second line" (putStrLn "first line" world) > > The 'world' parameter forces the two functions into the > order you want, because printing "second line" needs the > result of printing "first line" before it can be evaluated. > > However, writing complex applications with that kind of API > would drive you nuts, and would also be unsafe without some kind of strong guarantee that each single 'world' value is unique. (This is how they do it in Clean.) Imagine g :: World -> World g world = let world' = putStrLn "first line" world in putStrLn "second line" world -- oops, forgot the "'" > so instead you can say > > f :: IO () > f = do putStrLn "first line" > putStrLn "second line" > > and it means the exact same thing. /and/ it guarantees that 'world' cannot be accidentally duplicated because it is not directly accessible to the program, thus there is only one 'world' ever existing at the same time, thus all IO actions are cleanly sequenced according to the data dependencies. > Curiously enough, if you check out the reference > documentation at: > > > http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad- >ST.html#t%3ARealWorld > > ..., you'll find that a "World" type actually exists. Ben _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On 20/12/05, Benjamin Franksen <[hidden email]> wrote:
> On Tuesday 20 December 2005 20:58, Peter Simons wrote: > > Daniel Carrera writes: > > > I'm scared of monads :) I really don't know what a monad > > > is. > > > > Neither do I, but that doesn't mean that I can't use just > > fine. ;-) > > > > >> putStrLn :: String -> World -> World > > > > > > That seems less scary. > > > > Things become a lot clearer when you think about how to > > print _two_ lines with that kind of function. You'd write: > > > > f :: World -> World > > f world = putStrLn "second line" (putStrLn "first line" world) > > > > The 'world' parameter forces the two functions into the > > order you want, because printing "second line" needs the > > result of printing "first line" before it can be evaluated. > > > > However, writing complex applications with that kind of API > > would drive you nuts, > > and would also be unsafe without some kind of strong guarantee that each > single 'world' value is unique. (This is how they do it in Clean.) > Imagine > > g :: World -> World > g world = let world' = putStrLn "first line" world > in putStrLn "second line" world -- oops, forgot the "'" > I suppose it depends on one's perspective, and what the World type really looks like. If you're cheating by threading a trivial value, and getting what are supposed to be pure functions to have side effects, then this is a problem. If World is a suitable type for holding information about the actions to eventually perform based on user input, then this will work just fine (though it's likely a bug the way that it's written). To me, this view doesn't seem any less scary than the monadic approach. You've just moved the scary part (if any) into the World type. I believe that a type somewhat along the lines of [Request] -> [Response] was at one point used for this. At some point you should really stop caring exactly how it's implemented though, and simply regard these IO actions as the sum of their parts. You have a bunch of primitives (getChar :: IO Char, putChar :: Char -> IO (), etc) that describe actions to be performed, and some operations, the monad operations on IO included, for combining them into composite actions. A simple example of one of these combining operations is the sequencing operation: (>>) :: IO a -> IO b -> IO b If x and y are IO actions, then (x >> y) is just an IO action which performs x, throws away any result, and then performs y, returning the result of that. For example, (putStrLn xs) is an action which prints the string xs on the screen, and (putStrLn "Hello" >> putStrLn "World") will print the strings "Hello" and "World" on subsequent lines. What if we don't want to throw away the result of the first operation? Well, there is a slightly more complicated version of the sequencing operation for that: (>>=) :: IO a -> (a -> IO b) -> IO b Now, this might seem scary at first, but all that it is doing is chaining actions together in sequence. The expression (x >>= f) produces the action which executes the action x, and applies f to the result of that action, which gives a new action that it executes in turn. As an example, getLine :: IO String, is an action which gets a line of text from the user. (getLine >>= \x -> putStrLn x) is an action which gets a line of text from the user, and then prints it back out. By understanding the primitives and the combiners, it's possible to understand everything there is to know about IO in Haskell. You don't actually need to look at how it's implemented (and probably shouldn't rely on one implementation too much). Let the RTS worry about the data structures used to represent your actions, exposing the implementation details just makes things more complicated. This is not to say that understanding monads in general isn't worthwhile, it very much is. It's also not to say that monads should always be treated like black boxes, as most often they aren't at all black boxes. However, it's possible for the library designer to give you a monad whose inner workings you can't inspect directly, and in the case of IO, that's basically what has been done. It should be respected, because it actually simplifies matters not to worry about the implementation. - Cale _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Neil Mitchell
Hello Neil,
Tuesday, December 20, 2005, 11:52:51 PM, you wrote: NM> Hi, >> Hugs Interpreter only Suitable for learning. You'll need GHC for serious work. NM> This is putting Hugs down quite a bit. I personally prefer Hugs, and NM> use it for serious work (including developing a Haskell compiler, and NM> 4 years of academic study and counting). for me, Hugs and especiall WinHugs is an amazing tool to develop programs that then will be compiled by GHC. they have a greatest level o compatibility while Hugs loads programs 10 times faster than GHCi and have much more helpful environment (especially WinHugs 2005) -- Best regards, Bulat mailto:[hidden email] _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Sebastian Sylvan
On Tue, Dec 20, 2005 at 08:07:29PM +0100, Sebastian Sylvan wrote:
> I'm still looking for a good *practical* tutorial that I could > recommend to newcomers. > IO, data types and QuickCheck in the very first chapter, I say! Real > program examples from the get go, and go into the theory on why this > has been hard in FP before Haskell (or Monadic IO rather) much much > later, so as to not scare people away. Indeed, I have been wanting to write something like this for a long time. perhaps using ginsu or (a simplified) jhc as a long running example throughout the tutorial. unfortunatly my prose is worse than my code. But I think such a tutorial (book?) describing how to write a real-world haskell program from scratch without glossing over details like IO would be a really great addition to the haskell bookshelf. John -- John Meacham - ⑆repetae.net⑆john⑈ _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Peter Simons
On Tue, 2005-12-20 at 20:58 +0100, Peter Simons wrote:
> Curiously enough, if you check out the reference > documentation at: > > http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad-ST.html#t%3ARealWorld > > ..., you'll find that a "World" type actually exists. While that is true in GHC it is not required by Haskell. The concrete implementation of IO is compiler specific. Also worth noting is that there are (two that I know of) languages that employ an explicit world parameter to do IO: Clean and Mercury. Cheers, Bernie. _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Ben Franksen-2
On Tue, Dec 20, 2005 at 10:04:16PM +0100, Benjamin Franksen wrote:
> and would also be unsafe without some kind of strong guarantee that each > single 'world' value is unique. (This is how they do it in Clean.) > Imagine > > g :: World -> World > g world = let world' = putStrLn "first line" world > in putStrLn "second line" world -- oops, forgot the "'" A more scary example: getLine :: World -> (World, String) getTwoLines :: World -> (World, String, String) getTwoLines world = let (world', line1) = getLine world (world'', line2) = getLine world -- oops, should use world' here in (world'', line1, line2) So we forgot about world', but used line1, which was produced together with world'. Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Sebastian Sylvan
On Tue, 20 Dec 2005, Sebastian Sylvan wrote: > Monadic IO is pretty darn cool, sadly that means that many tutorial > authors are tempted to spend pages upon pages explaining exactly why > it's cool and how it works, but that is NOT what most people starting > out with the language need to read. > > I'm still looking for a good *practical* tutorial that I could > recommend to newcomers. > IO, data types and QuickCheck in the very first chapter, I say! Real > program examples from the get go, and go into the theory on why this > has been hard in FP before Haskell (or Monadic IO rather) much much > later, so as to not scare people away. Starting with IO in Haskell is like starting LaTeX with rotating text and making it colorful. Indeed IO _is_ complicated regardless of whether it is modelled by Monads in Haskell or differently in other languages. Beginners should start with non-monadic functions in order to later avoid IO in their functions whereever possible. There are a lot of non-IO applications a beginner can start with, such as using Hugs or GHCi as a programmable calculator. _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Neil Mitchell
Neil Mitchell <[hidden email]> writes:
> I would have actually said Hugs, and especially the Windows front end > WinHugs was a lot more suitable for beginners than GHC, but the wiki > page very much gives the other impression. Which page are you referring to? I went to look, but couldn't find any page discussing the compiler/interpreter options with reasonable detail and focus. -k -- If I haven't seen further, it is by standing in the footprints of giants _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Henning Thielemann
Henning Thielemann wrote:
> Starting with IO in Haskell is like starting LaTeX with rotating text and > making it colorful. Not at all! > Indeed IO _is_ complicated regardless of whether it is > modelled by Monads in Haskell or differently in other languages. Rubbish! 10 PRINT "WHAT IS YOUR NAME?" 20 INPUT NAME IO isn't complicated in BASIC. > Beginners should start with non-monadic functions in order to later avoid > IO in their functions whereever possible. Whilst localising IO to a small part of the program is generally a good idea, beginners should not be scared off by the thought that IO in Haskell is so hard it has to be covered on page 94. This is not the case. It should be introduced on page 1. If people want Haskell to be treated as a practical language, not just something for doing academic teaching and research with, it should be taught as a practical language - which means that things like IO and space/time usage come to the forefront. -- Robin _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Free forum by Nabble | Edit this page |