Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error that is causing your compile problems is that you are directly casting an expression to the type <code>Either (IO ()) (String, [String])</code> when it is not an <code>Either</code> value. (The compiler is not outputting a very helpful error message.)</p> <p>To create an Either value [1], we use the data constructors <code>Left</code> and <code>Right</code>. Convention (from the library page) is that errors are a Left value, while correct values are a Right value.</p> <p>I did a quick rewrite of your arg checking function as </p> <pre><code>checkArgs :: [String] -&gt; Either String (String, [String]) checkArgs args = case args of [] -&gt; Left "No arguments given. See --help for more info." _ -&gt; let (params@(param:_),rest) = span (\(c:_) -&gt; c=='-') args in if length params &gt; 1 then Left ("No arguments given for " ++ param) else let (pArgs,_) = span (\(c:_) -&gt; c/='-') rest in Right (param, pArgs) </code></pre> <p>Note that the arg checking function does not interact with any external <code>IO ()</code> library functions and so has a purely functional type. In general if your code does not have monadic elements (<code>IO ()</code>), it can be clearer to write it in purely functional style. (When starting out in Haskell this is definitely something I would recommend rather than trying to get your head around monads/monad transformers/etc immediately.)</p> <p>When you are a little more comfortable with monads, you may want to check out <code>Control.Monad.Error</code> [2], which can wraps similar functionality as <code>Either</code> as a monad and would encapsulate some details like <code>Left</code> always being computation errors.</p> <p>[1] <a href="http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Either.html" rel="nofollow">http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Either.html</a></p> <p>[2] <a href="http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/Control-Monad-Error.html" rel="nofollow">http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/Control-Monad-Error.html</a></p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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