4 ms·
As a complete and total haskell noob, I am unable to even get through your syntax examples: Prelude> sumOfElements [] = 0 <interactive>:12:18: parse error on
by hamburglar 13y ago
As a complete and total haskell noob, I am unable to even get through your syntax examples:
Prelude> sumOfElements [] = 0
<interactive>:12:18: parse error on input `='
- tdinkar 13y agoStart with downloading the hydra.hs file I linked to in the end. Haskell is not like ruby, it's a bit harder to define functions in the interpreter. It's easier to put them in a .hs file and then :load file.hs
- navbaker 13y agoSince this is a 101, you might want to put your Haskell setup URL and any file dependencies/explanations of Haskell's idiosyncrasies at the top of the tutorial. A 101 is aimed at people who don't know anything about the language and assuming knowledge is a good way to ensure folks get frustrated and never come back.
- coolsunglasses 13y agoYou're using the REPL, where every operation is basically happening in a do monad. If you get an error like that where you intend to define something, use let. like: let sumOfElements [] = 0
- gizmo686 13y agoI believe you mean that every operation is happening in the IO monad, and you input is being interpreted as if it was in a do block.
- deleted 13y ago[deleted]
- coolsunglasses 13y agoSorry, yes, misspoke (so to speak) because I had friends waiting for me to queue a Dota 2 game :)
- gizmo686 13y agoThis defiantly falls under Haskell not being noob friendly. If you are in the REPL, you want to do `let sumOfElements [] = 0` If you want multiline input, you open with `:{` and close with `:}`. Both of these need to be on their own line. For example: Prelude>:{ Prelude| let sum [] = 0 Prelude| sum (x:xs) = x + sum xs Prelude|:} As tdinkar points out, it is often easier to define your functions if a file and load that file from the REPL.
- hamburglar 13y agoaha, i tried using 'let' on the assumption that he was just being brief, but I put a 'let' in front of each of the pattern-matching function signatures, which didn't work. Thanks. edit: I take your last comment as "when using the REPL, it is easier not to use the REPL." :D
- brandonbloom 13y agoSince Haskell has a strong divide between compile and runtime, the REPL is this weird pseudo-runtime. It's best not to think of it like a REPL except for very simple use cases and instead think of it like a command prompt that you can evaluate some portion of Haskell in. If you type `:help` you'll see all of the colon-commands that make up the command language. I'm not a Haskell expert, but my naive workflow tends to be a lot of usage of `:reload`. As a Lisper, I kinda feel like the colon commands should have been the default (sans colon) and one of the commands should have been `eval <haskel code>`.
- mercuryrising 13y agoCheck out IHaskell - https://github.com/gibiansky/IHaskell https://github.com/gibiansky/IHaskell It lets you do multiline stuff, and you get to see the output right away. You don't need let, or to repeat the "main = do ..." every time you want to run a block of code. I think it's really helpful when you're starting out.
- andrus 13y agoNeat, I knew about `:set +m` for enabling multiline input, but not `:{ ... }:`.