[Haskell-beginners] help understanding error from attempt at CIS 194 : Homework 7 - indexJ
Dustin Lee
qhfgva at gmail.com
Thu Jan 8 19:01:49 UTC 2015
Here's what I have so far for JoinList.hs: (
http://www.seas.upenn.edu/~cis194/spring13/hw/07-folds-monoids.pdf)
====
module JoinList
where
import Data.Monoid
import Sized
data JoinList m a = Empty
| Single m a
| Append m (JoinList m a) (JoinList m a)
deriving (Eq, Show)
tag :: Monoid m => JoinList m a -> m
tag Empty = mempty
tag (Single m a) = m
tag (Append m _ _) = m
(+++) :: Monoid m => JoinList m a -> JoinList m a -> JoinList m a
(+++) x y = Append (tag x <> tag y) x y
indexJ :: (Sized b, Monoid b) => Int -> JoinList b a -> Maybe a
indexJ _ Empty = Nothing
indexJ i (Single m a)
| i == 0 = Just a
| otherwise = Nothing
indexJ i (Append m x y)
| (getSize (tag x)) >= i = indexJ i x
| otherwise = indexJ (i - (getSize (tag x))) y
=====
Here is the error I'm getting. Haven't been able to make sense of it yet.
*Sized> :load "JoinList.hs"
[1 of 2] Compiling Sized ( Sized.hs, interpreted )
[2 of 2] Compiling JoinList ( JoinList.hs, interpreted )
JoinList.hs:50:21:
Could not deduce (b ~ Size)
from the context (Sized b, Monoid b)
bound by the type signature for
indexJ :: (Sized b, Monoid b) => Int -> JoinList b a ->
Maybe a
at JoinList.hs:44:11-63
`b' is a rigid type variable bound by
the type signature for
indexJ :: (Sized b, Monoid b) => Int -> JoinList b a -> Maybe a
at JoinList.hs:44:11
Expected type: JoinList Size a
Actual type: JoinList b a
In the first argument of `tag', namely `x'
In the first argument of `getSize', namely `(tag x)'
In the first argument of `(>=)', namely `(getSize (tag x))'
Failed, modules loaded: Sized.
thanks!
--
Dustin Lee
qhfgva=rot13(dustin)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150108/ca08cea5/attachment.html>
More information about the Beginners
mailing list