Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't seem to implement Either correctly
    primarykey
    data
    text
    <p>Alright so here's my current code:</p> <pre><code>import System.IO import System.Environment import System.Directory main = do unfiltered &lt;- getArgs ; home &lt;- getHomeDirectory ; let db = home ++ "/.grindstone" case unfiltered of (x:xs) -&gt; return () _ -&gt; error "No command given. See --help for more info." command:args &lt;- getArgs createDirectoryIfMissing True db let check = case args of [] -&gt; error "No arguments given. See --help for more info." _ -&gt; do let (params@(param:_),rest) = span (\(c:_) -&gt; c=='-') args if length params &gt; 1 then error ("No arguments given for " ++ param) else do let (pArgs,_) = span (\(c:_) -&gt; c/='-') rest return (param, pArgs) :: Either (IO ()) (String, [String]) let add = print "sup" let cmds = [("add", add)] let action = lookup command cmds case action of Nothing -&gt; error "Unknown command." (Just action) -&gt; action </code></pre> <p>The main problem is with check. I tried implementing the Either type since I want it to either error out, or return something for another function to use, but, it's currently erroring out with:</p> <pre><code>grindstone.hs:21:23: No instance for (Monad (Either (IO ()))) arising from a use of `return' at grindstone.hs:21:23-43 Possible fix: add an instance declaration for (Monad (Either (IO ()))) In the expression: return (param, pArgs) :: Either (IO ()) (String, [String]) In the expression: do { let (pArgs, _) = span (\ (c : _) -&gt; ...) rest; return (param, pArgs) :: Either (IO ()) (String, [String]) } In the expression: if length params &gt; 1 then error ("No arguments given for " ++ param) else do { let (pArgs, _) = ...; return (param, pArgs) :: Either (IO ()) (String, [String]) } </code></pre> <p>I'm only starting out in haskell and haven't dealt too much with monads yet so just thought I'd ask on here. anyone have any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload