<div dir="ltr"><div>Ahhh....  I'm using the size function now and at least I don't get any compile errors anymore.....   Now to check the code actually works.<br><br></div>Thanks!<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 8, 2015 at 12:26 PM, divyanshu ranjan <span dir="ltr"><<a href="mailto:idivyanshu.ranjan@gmail.com" target="_blank">idivyanshu.ranjan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Dustin,<div><br></div><div>(tag x) return something of type b which implements Sized and Monoid. </div><div>Where as getSize takes value of type Size. </div><div>Hence the error. b might not be equal to Size. Thus compiler is complaining. </div><div><br></div><div>Given b is (Sized b), how one can convert it into Size ? </div><div><br></div><div><br></div><div><div><br></div><div>Thanks</div><div>Divyanshu Ranjan</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Jan 9, 2015 at 12:31 AM, Dustin Lee <span dir="ltr"><<a href="mailto:qhfgva@gmail.com" target="_blank">qhfgva@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Here's what I have so far for JoinList.hs:   (<a href="http://www.seas.upenn.edu/~cis194/spring13/hw/07-folds-monoids.pdf" target="_blank">http://www.seas.upenn.edu/~cis194/spring13/hw/07-folds-monoids.pdf</a>)<br><div><br>====<br>module JoinList<br><br>where<br><br>import Data.Monoid<br>import Sized<br><br>data JoinList m a = Empty<br>                  | Single m a<br>                  | Append m (JoinList m a) (JoinList m a)<br>     deriving (Eq, Show)<br><br><br>tag :: Monoid m => JoinList m a -> m<br>tag Empty           = mempty<br>tag (Single m a)    = m<br>tag (Append m  _ _) = m<br><br>(+++) :: Monoid m => JoinList m a -> JoinList m a -> JoinList m a<br>(+++) x y = Append (tag x <> tag y) x y<br><br><br>indexJ :: (Sized b, Monoid b) => Int -> JoinList b a -> Maybe a<br>indexJ _ Empty  = Nothing<br>indexJ i (Single m a) <br>    | i == 0    = Just a<br>    | otherwise = Nothing<br>indexJ i (Append m x y)<br>    | (getSize (tag x)) >= i  = indexJ i x<br>    | otherwise               = indexJ (i - (getSize (tag x))) y<br><br>=====<br><br></div><div>Here is the error I'm getting.   Haven't been able to make sense of it yet.<br><br>*Sized> :load "JoinList.hs"<br>[1 of 2] Compiling Sized            ( Sized.hs, interpreted )<br>[2 of 2] Compiling JoinList         ( JoinList.hs, interpreted )<br><br>JoinList.hs:50:21:<br>    Could not deduce (b ~ Size)<br>    from the context (Sized b, Monoid b)<br>      bound by the type signature for<br>                 indexJ :: (Sized b, Monoid b) => Int -> JoinList b a -> Maybe a<br>      at JoinList.hs:44:11-63<br>      `b' is a rigid type variable bound by<br>          the type signature for<br>            indexJ :: (Sized b, Monoid b) => Int -> JoinList b a -> Maybe a<br>          at JoinList.hs:44:11<br>    Expected type: JoinList Size a<br>      Actual type: JoinList b a<br>    In the first argument of `tag', namely `x'<br>    In the first argument of `getSize', namely `(tag x)'<br>    In the first argument of `(>=)', namely `(getSize (tag x))'<br>Failed, modules loaded: Sized.<br clear="all"></div><div><br><br><br></div><div>thanks!<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div><br>-- <br><div>Dustin Lee<br>qhfgva=rot13(dustin)</div>
</div></font></span></div>
<br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Dustin Lee<br>qhfgva=rot13(dustin)</div>
</div>