10 ms·
Reading Simple Haskell
- Tehnix 9y agoUnrelated: I'm obviously quite biased, but I generally like Haskell code for pseudo code like things, because it does away with a lot of syntax specific cruft, and stays close to the math it's usually talking about. Also, readers might be interested in A Tour of Go in Haskell, which is the concurrency chapter of A Tour of Go, but just...in Haskell - https://a-tour-of-go-in-haskell.syocy.net/en_US/index.html https://a-tour-of-go-in-haskell.syocy.net/en_US/index.html.
- spraak 9y agoWow that resource is super clever and useful, I wish it had the full "Tour"!
- Tehnix 9y agoIt was more or less just posted, but I could imagine there is plans for the rest of the content to be ported also. I might help with that if I get any time during Christmas :x
- pjmlp 9y agoRegarding concurrency in Haskell, there is a very good book from Simon Marlow, "Parallel and Concurrent Programming in Haskell".
- deleted 9y ago[deleted]
- hoprocker 9y agoAgreed -- I found Haskell most confusing at first because of the lack of syntax. My brain kept wondering where the rest of the syntax was. Not to be too dramatic, but I think Haskell is kind of like programming "poetry" in this regard.
- leshow 9y agoWhen I first start I though there was so MUCH syntax, (->), (<*>), (<$>), (>>=), (.), ($), etc I realized pretty early on all these were just functions, that was cool experience for me. Even the types are sort of functions.
- lalaithion 9y agoOne fun thing is how -> is basically just an infix operation that takes two types as arguments and returns a new type. add :: (->) Int Int add x y = x + y
- leshow 9y agoIt's the function type, data (->) a b. It is commonly written in infix notation though.
- junkscience2017 9y agoGo is impoverished compared to Haskell but not when it comes to concurrency. The Haskell analogues for these concurrency primitives seem laborious...and they were even moreso prior to the advent of the `async` library.
- Tehnix 9y agoA commenter on /r/haskell[0] noted that there is actually a library that mimics Go Channels a bit closer, called GoChan[1]. That said, I think `async` is the idiomatic choice, so it probably makes more sense to keep it. [0] https://www.reddit.com/r/haskell/comments/7ilhb9/a_tour_of_go_in_haskell/ https://www.reddit.com/r/haskell/comments/7ilhb9/a_tour_of_g... [1] https://hackage.haskell.org/package/gochan-0.0.2/docs/Control-Concurrent-GoChan.html https://hackage.haskell.org/package/gochan-0.0.2/docs/Contro...
- bjoli 9y agoWhich is strange. It should be possible to implement proper CML-style concurrency in Haskell, which is strictly more expressive than the go concurrency model.
- speps 9y agoI only started Haskell since the 1st day of Advent of Code this year. I didn't see that mentioned much either in the article or other articles, but Haskell is like Python and has significant whitespace to determine scope. The error messages related to this aren't always clear...
- Tehnix 9y agoThe error messages should have improved a bit with GHC 8.2[0], you might wanna check that out if you aren't already using it. For stack that'll mean using the nightlies though (e.g. `resolver: nightly-2017-12-09`). [0] https://twitter.com/raichoo/status/825045995490795521 https://twitter.com/raichoo/status/825045995490795521
- culturedsystems 9y agoOne thing this doesn't mention, which might be useful to know, is that Haskell is indentation-sensitive. For instance, those examples using "let" won't compile if the lines beginning with "let" and "in" aren't indented. I'd be interested if anyone knows of a simple guide to Haskell's indentation rules - I still find it trips me up now and then.
- tome 9y ago> I'd be interested if anyone knows of a simple guide to Haskell's indentation rules - I still find it trips me up now and then. The "simple" way I deal with it is to use Emacs and press TAB until things look right :)
- Tehnix 9y agoRe indentation, you might find these two useful https://en.wikibooks.org/wiki/Haskell/Indentation https://en.wikibooks.org/wiki/Haskell/Indentation and http://echo.rsmw.net/n00bfaq.html http://echo.rsmw.net/n00bfaq.html.
- kkmx 9y agoThat helped thanks!
- masklinn 9y ago> Haskell is indentation-sensitive. That's not really true, at least not in the way Python is. Haskell is actually defined using "braceful" syntax, and that syntax can be used anywhere (and is useful for code generation); on top of that it has Layout Rules[0]. Basically: Any time a "where", "let", "do" or "of" keyword is not followed by a brace, an implicit one is inserted and the indentation of the next lexeme (non-comment non-whitespace item) is noted[1] For any subsequent line, * if it's indented by the same amount as the one noted, a semi-colon is prepended * if it's indented by less than the noted amount, a closing brace is prepended A closing brace is also inserted when encountering an illegal lexeme (for the current structure) where a a closing brace would be legal. [0] https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-210002.7 https://www.haskell.org/onlinereport/haskell2010/haskellch2.... [1] except if the indentation of the next non-whitespace lexeme is less than the current indentation level, then an empty block is inserted, and layout processing for the current scope continues
- mark_l_watson 9y agoNice guide for learning to read Haskell code! You have one minor type: "tree1123 :: IntTree tree ="
- gilmi 9y agothanks! fixed.
- hellofunk 9y agoI once downloaded a python script, ran it with some input, and got a result. Curious, I opened the script in Emacs, which then opened it into python mode. As is my habit, I indented the whole file, which did basic white space changes to it according to python mode. I didn't realize I did this at first, and I saved and exited the script, then played around with it some more. Still got results, everything seemed the same. But when I tried it with the same input as originally, it was a different return result. This took a while to figure out, until I realized that emacs changed the indentation of just one line, because the author had apparently not followed the typical idioms or conventions of indenting python in some way. That merely opening, beautifying, and saving a file could change program output with no errors has turned me off of white space sensitive syntax ever since. Which is partly why OCaml gets some bias from me over Haskell.
- mlevental 9y agohonestly it's bananas. I can't for the life of understand how such a poor form over function decision was ever made by an engineer. the number of bugs (>0) this introduces into production code every year is reason enough (imho the only relevant metric) to prefer braces. are block delimiting braces really that onerous???
- coldtea 9y agoBecause braces don't introduce bugs? You can just as easily omit braces in a if/for etc statement and have a bug, or close the wrong brace at the wrong point (and also introduce a bug).
- _0ffh 9y agoThis site breaks the zoom function in Firefox. Please be considerate towards the visually impaired, and don't break zoom on one of the few browsers that actually even have a somewhat useful zoom function!
- quadrangle 9y agoWhile I agree STRONGLY, I just tested after seeing your comment and it led me to try the Reader mode in FF which worked perfectly and thus allows full zooming of this site.
- _0ffh 9y agoWow, thank you for introducing me to that feature!
- sridca 9y agoIt doesn’t even work on iOS safari.
- gilmi 9y agoYou can view this as markdown on github[0] [0]: https://github.com/soupi/rfc/blob/master/reading_haskell.md https://github.com/soupi/rfc/blob/master/reading_haskell.md
- gilmi 9y agoI'm sorry for that. I'll try to fix this when I can. For now you can view the markdown document instead of the slides here: https://github.com/soupi/rfc/blob/master/reading_haskell.md https://github.com/soupi/rfc/blob/master/reading_haskell.md
- bachmeier 9y agoHaskell is one of the few major languages I haven't used much. I find this to be very helpful. Sometimes I look at the Pandoc source and wonder what the hell I'm looking at.
- swlkr 9y agoI've always been confused when reading Haskell snippets on the web, this really cleared things up for me!
- cygned 9y agox +- y = (x + x) - (y + y) That's crazy. I should learn Haskell (again).
- mlevental 9y agowhat exactly is crazy about this?
- runeks 9y agoThe simplicity with which a new operator is defined.
- cygned 9y agoThis. Incredible elegant. I always enjoy these types of things when programming Lisp.
- akhilcacharya 9y agoI think this is a downside. It just makes reading new code that uses esoteric symbols defined elsewhere.
- gilmi 9y agoThis[0] operator glossary reviews the most used operators. [0]: https://haskell-lang.org/tutorial/operators https://haskell-lang.org/tutorial/operators
- Tehnix 9y ago`+-` here is an entirely new operator though. The shuffling of arguments might look a bit weird though, it could also be written (+-) x y = (x + x) - (y + y) Symbol operators are automatically infix though, and you can make them normal using (), same as backticks make normal functions infix, `a la 2 `plus` 3.
- notsgnik 9y agonice guide
- weavie 9y agoHaskell can be very readable and elegant, but what I do find frustrating is when research papers show sample Haskell, but it's not quite Haskell. They just can't seem to resist the urge to replace various operators and types with their own non-alphanumeric symbols, thus making what should be reading simple code into some kind of hieroglyphic translation exercise..
- leshow 9y agoThere are a bunch build into the language, I think a lot of libraries take their queue from there. Still, after you get over the initial hurdle of like <$> == fmap. It's not so bad.
- nybble41 9y ago> when research papers show sample Haskell, but it's not quite Haskell For the most part the code in the research papers actually _is_ valid Haskell, provided you enable the -XUnicodeSyntax extension and include a few extra modules. Haskell 98 permits Unicode symbols and identifiers; the extension covers the handful of symbols which are built in to the language or enabled by other extensions. You can find a full list here: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#unicode-syntax https://downloads.haskell.org/~ghc/latest/docs/html/users_gu... Personally I prefer Unicode symbols and tend to use them whenever possible. I have some XCompose rules configured to make them easier to type. Unfortunately, I have yet to find a comparable input system for Windows.
- nigwil_ 9y agoI like the content but: I can't link to the slide because of the way these pages are defined: slide 11: The presented argument order in the ASCII-art of Red, Blue, Green I think should be Red, Green, Blue to match the usual initialism. I could not find a way to submit a pull-request for this presentation, and my search-fu on github failed to find the associated repo, and there were no links I could find in the presentation to submit comments.
- gilmi 9y agoThanks! fixed. You can find the document and repo here: https://github.com/soupi/rfc/blob/master/reading_haskell.md https://github.com/soupi/rfc/blob/master/reading_haskell.md