9 ms·
Try Haskell: An interactive tutorial in your browser
- hartator 14y agoYou constructed a list! Well done, that was tricky syntax. You used the (:) function. It takes two values, some value and a list, and constructs a new list out of them. We call it 'cons' for short. No it's not: > 'a' : [] => "a"
- kryptiskt 14y agoWhat's the problem? A string in Haskell is a list of chars[1]. So you can construct a string by consing chars to an empty list. Or is there something else you object to? [1] Which incidentally is a reason to avoid using it for anything serious. Text is the better representation of text, and ByteString is better for everything else.
- tkahn6 14y agoWould you accept: > 'a' : "" => "a" Because that's what you did.
- sold 14y agoIn Haskell "a" is the same as ['a']
- niggler 14y agoAs is usually the case with interactive tutorials, unexpected behavior shows up before the clarifying example. Later they show the equivalence of strings "a" and list of chars ['a']
- hp50g 14y agoI've been through this a few times. It puts me off Haskell even more each time. Bear in mind I'm pretty handy with obscure obfuscated by default things like RPL, Forth and Perl and occasionally common lisp.
- tome 14y ago> It puts me off Haskell even more each time. How come?
- hp50g 14y agoIt's not the tutorial specifically - more Haskell itself: Syntax feels slightly horrid. Doesn't seem to visually or syntactically scale well with the size of the problem at hand. Some of it is plain ugly (records). It's harder than the others resulting in more head scratching. Debugging is slightly painful. These are all IMHO. To be fair, I'm going to do the tutorial again this afternoon.
- dons 14y agoWhat do you mean "syntax doesn't syntactically scale" ?
- hp50g 14y agoA single function/expression tends to drag over too much space for my liking. It's hard to break down some of them into functional units that fit in my head properly. Perhaps I'm just thick :) Look at List.hs (sort/sortBy) for what I mean: http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-List.html http://hackage.haskell.org/packages/archive/base/latest/doc/...
- pilgrim689 14y agoThat sortBy is split into 6 sub-functions, all 2 to 4 lines each. You want it more broken down?
- hp50g 14y agoFair point. I will do the tutorial again! :) I might get it if I keep trying. (ironically I did an engineering degree which was rather maths heavy so I should get this).
- DodgyEggplant 14y agohttp://book.realworldhaskell.org/read/ http://book.realworldhaskell.org/read/
- danieldk 14y agoObligatory LYAH link :): http://learnyouahaskell.com/ http://learnyouahaskell.com/ I gave this book to a lot of programmer friends, and most were very enthusiastic after finishing the book. Even if you never use Haskell in the real world, learning its abstractions makes you a better programmer (and sometimes annoyed by the lack of type system features in other languages ;)).
- daGrevis 14y agoI have read some tutorials about Haskell (to be completely honest, 60% of "Learn haskell for great good" twice). Still, I need to stop and think for few seconds to write something in it.
- DanWaterworth 14y agoIt does take a while, but, for me at least, it did eventually become natural.
- esalman 14y agoThrows a bunch of jQuery errors in Firefox Aurora. Works OK in Chrome.
- sek 14y agoMake an interactive tutorial for monads. After 5 articles about it, who were all very different, I still don't know how to code one.
- merijnv 14y agoThe majority of monad "tutorials" are notoriously terrible. Have you read "You Could Have Invented Monads! (And Maybe You Already Have.)"? If no, you should try it, it's a rather nice article. If yes, where did you get stuck with trying to implement your own?
- merijnv 14y agoBah, I just noticed I completely forgot to include the link for the lazy: http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html http://blog.sigfpe.com/2006/08/you-could-have-invented-monad...
- tinco 14y agoWhy do you want to code one? Monads are a class of solutions to certain problems. Look at your problem and solve it using regular haskell. Now look at your solution, it might be that the set of functions that define your solution describe a monad. Is this relevant? Usually not, unless you are developing a highly reusable library. An example: almost every FP course has the students define the Maybe datatype with its accompanying functions. In Haskell Maybe is an instance of Monad, but you don't need to know that to use or make Maybe, it just turns out that the Maybe solution is in that class of Monads.
- nilkn 14y agoLook at Parsec to see how powerful monadic code can be. That single-handedly cleared up the issue for me when I was learning Haskell.
- CJefferson 14y agoOoo, let's try something functional: > map reverse No instance for (GHC.Show.Show ([[a0]] -> [[a0]])) arising from a use of `M1690418375.show_M1690418375' Possible fix: add an instance declaration for (GHC.Show.Show ([[a0]] -> [[a0]])) Hmm....
- dons 14y ago> :t map reverse :: [[a]] -> [[a]] > show (map reverse) No instance for (GHC.Show.Show ([[a0]] -> [[a0]])) You can't show functions. Pass an argument: > map reverse ["test","this"] => ["tset","siht"]
- ent 14y agoI'm not sure what you expected. It's just saying it doesn't know how to print a function that takes as input a list of lists of type a0 and returns a list of lists of type a0. Try map reverse ["abc", "123"] instead, which it does know how to print.
- CJefferson 14y agoI don't know what I expected. I don't know Haskell. I am vaguely familiar with other functional languages and thought I would explore. However, this system (or Haskell) are not super-friendly to exploring currying it seems.
- jerf 14y agoAs other people are asking, though, what did you expect? Serious question. What you got was perhaps phrased in terms you're not used to, but there's not much else you could have gotten.
- CJefferson 14y agoI understand curried functions are a very common thing to build in functional languages. So some nicely 'pretty printed' version would be nice. Or at least the least some kind of "can't print a function" in a nice way. This looks like the kind of thing I get when my C linker has horribly choked on my code, what is the benefit of displaying: M1690418375.show_M1690418375 to the user? What should I do with that piece of information? How do I 'add an instance declaration for (GHC.Show.Show ([[a0]] -> [[a0]]))'? I'm guessing that this is basically "suggesting" I implement printing for all functions? Or just for map? I'm not sure. I'm sure I'm not doing it, and it may well not even be possible?