3 ms·
I have Haskell experience and would love to do these exercises, but I am struggling with the environment. For example, Set1 tells me to make a function fiveRan
by ridiculous_fish 11y ago
I have Haskell experience and would love to do these exercises, but I am struggling with the environment.
For example, Set1 tells me to make a function fiveRands and then "check my answers;" how do I do that? I know enough Haskell to do something like:
main = putStrLn $ show fiveRands
but putStrLn is not part of MCPrelude so this doesn't compile, and the instructions say explicitly "Do not import any other modules."
I'm excited to try these. Please add some more hand-holding to get me and others over the tooling and environment issues.
- tetrep 11y agoit doesn't look like their prelude has any stdout printing functions, so it's probably easiest to test your code in a repl. you can check what functions they do give you by looking at the stuff before the "where" here: https://github.com/mightybyte/monad-challenges/blob/gh-pages/src/MCPrelude.hs https://github.com/mightybyte/monad-challenges/blob/gh-pages... as for verifying your results, they give you the product of the 5 numbers at the bottom of the page (since you're starting from a predetermined seed, the 5 numbers you generate are known)
- fabianhjr 11y agoI started this challenges and just use GHCi to check/eval things. (> ghci set1.hs for example)
- rntz 11y agoIgnore the instructions and grab putStrLn if you need it in order to check your work. The instructions about not using other modules are there to avoid you "cheating". Looking at your work is definitely not cheating and will not prevent you from learning :). Also, just typing "fiveRands" and hitting ENTER at the repl will show you the value of fiveRands (or any other expression).
- dllthomas 11y ago"or any other expression" To be more precise, any other expression with an appropriate type. That's `a` or `IO a`, where `a` is an instance of `Show`. Most things that can reasonably be Shown already have a `Show` instance, but some things (like functions) can't really. This is relevant when the REPL shows an error like: <interactive>:2:1: No instance for (Show (t0 -> a0)) (maybe you haven't applied enough arguments to a function?) arising from a use of ‘print’ In the first argument of ‘print’, namely ‘it’ In a stmt of an interactive GHCi command: print it
- mightybyte 11y agoHi, I was assuming that people would do their playing around and answer checking in ghci. MCPrelude does not export putStrLn because it is an IO function, which is a monad and I specifically wanted to hide all the prelude's monad stuff. I suggest loading your file in ghci with "ghci Set1.hs". Then you can just type "fiveRands" at the ghci prompt and it will show you the values.
- ridiculous_fish 11y agoThanks! It would be great to walk through this, in the same way that it shows the shell commands for installation under "Getting Started." I hardly ever use the repl because I prefer to keep my tests around. I'm sheepish to admit this, but I only just now learned that you can pass a file to ghci.