<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Got it. I was mistaken in what the final "Unit c =>" meant.
    Thanks Bob!<br>
    <br>
    <div class="moz-cite-prefix">Em 21/05/14 03:28, Bob Ippolito
      escreveu:<br>
    </div>
    <blockquote
cite="mid:CACwMPm9mZ5pcmCmjDc7UmCnw8qL4ELkVBaCt4P5yN+DNwWWkXg@mail.gmail.com"
      type="cite">The trouble is that your specification says that Unit
      c is the return type (the caller can choose any Unit instance),
      but this implementation can only evaluate to a Prelude.Double. One
      way to solve this is to add a fromDouble :: Double -> Unit
      a and wrap the expression with that in order to satisfy Unit c.
      <div>
        <br>
        On Wednesday, May 21, 2014, Dimitri DeFigueiredo <<a
          moz-do-not-send="true" href="mailto:defigueiredo@ucdavis.edu">defigueiredo@ucdavis.edu</a>>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          Hi All,<br>
          <br>
          I'm trying to write a simplified dimensional library where
          where quantities in meters, seconds and meters/second can all
          co-exist adjusting their respective units when multiplied
          and/or divided.<br>
          <br>
          Also, meter+meter is allowed, but meter+second should cause
          the type checker to complain.<br>
          <br>
          This is a bit like a *much* simplified version of the Units
          library. However, I am having trouble understanding why my
          instance declaration below appears to be under specified.
          Here's the code:<br>
          <br>
          ------------<br>
          module Dimensional where<br>
          import qualified Prelude<br>
          <br>
          -- A Group allows you to add and subtract (but not multiply or
          divide)<br>
          class Group a where<br>
          <br>
              (+) :: a -> a -> a<br>
          <br>
              (-) :: a -> a -> a<br>
              x - y = x + negate y<br>
          <br>
              negate              :: a -> a<br>
              negate x             = fromInteger 0 - x<br>
          <br>
              fromInteger         :: Prelude.Integer -> a<br>
          <br>
          class Unit a where<br>
          <br>
              (*) :: (Unit a, Unit b, Unit c) => a -> b -> c<br>
              (/) :: (Unit a, Unit b, Unit c) => a -> b -> c<br>
              toDouble :: a -> Prelude.Double<br>
          <br>
          instance Unit Prelude.Double where<br>
          <br>
              (*) x y    = (Prelude.*) x (toDouble y)   -- <-----
          Error here<br>
              (/) x y    = (Prelude./) x (toDouble y)<br>
              toDouble x = x<br>
          <br>
          ------------<br>
          GHC complains as follows:<br>
          <br>
              Could not deduce (c ~ Prelude.Double)<br>
              from the context (Unit Prelude.Double, Unit b, Unit c)<br>
                bound by the type signature for<br>
                           * :: (Unit Prelude.Double, Unit b, Unit c)
          =><br>
                                Prelude.Double -> b -> c<br>
                at /code/haskell/dimensional.hs:25:5-43<br>
                `c' is a rigid type variable bound by<br>
                    the type signature for<br>
                      * :: (Unit Prelude.Double, Unit b, Unit c) =><br>
                           Prelude.Double -> b -> c<br>
                    at /code/haskell/dimensional.hs:25:5<br>
              In the first argument of `(Prelude.*)', namely `x'<br>
              In the expression: (Prelude.*) x (toDouble y)<br>
              In an equation for `*': * x y = (Prelude.*) x (toDouble y)<br>
          <br>
          Any pointers would be much appreciated!<br>
          <br>
          Thanks,<br>
          <br>
          Dimitri<br>
          <br>
          <br>
          _______________________________________________<br>
          Beginners mailing list<br>
          <a moz-do-not-send="true">Beginners@haskell.org</a><br>
          <a moz-do-not-send="true"
            href="http://www.haskell.org/mailman/listinfo/beginners"
            target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>