Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  help understanding error from attempt at CIS     194 : Homework
      7 - indexJ (Dustin Lee)
   2. Re:  help understanding error from attempt at CIS 194 :
      Homework 7 - indexJ (divyanshu ranjan)
   3. Re:  help understanding error from attempt at CIS 194 :
      Homework 7 - indexJ (Dustin Lee)


----------------------------------------------------------------------

Message: 1
Date: Thu, 8 Jan 2015 12:01:49 -0700
From: Dustin Lee <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] help understanding error from attempt at
        CIS     194 : Homework 7 - indexJ
Message-ID:
        <CAN3sYc34mh5=3ilravejn1urq2qujqafmeucd0lz+v6dtpv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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-0001.html>

------------------------------

Message: 2
Date: Fri, 9 Jan 2015 00:56:44 +0530
From: divyanshu ranjan <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] help understanding error from attempt
        at CIS 194 : Homework 7 - indexJ
Message-ID:
        <CAL9hw259N4t7S=vaTytOkgoVJ=VjrbuLJp=566csyc0wgmp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Dustin,

(tag x) return something of type b which implements Sized and Monoid.
Where as getSize takes value of type Size.
Hence the error. b might not be equal to Size. Thus compiler is
complaining.

Given b is (Sized b), how one can convert it into Size ?



Thanks
Divyanshu Ranjan


On Fri, Jan 9, 2015 at 12:31 AM, Dustin Lee <[email protected]> wrote:

> 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)
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150109/d5f1c33f/attachment-0001.html>

------------------------------

Message: 3
Date: Thu, 8 Jan 2015 12:32:46 -0700
From: Dustin Lee <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] help understanding error from attempt
        at CIS 194 : Homework 7 - indexJ
Message-ID:
        <CAN3sYc1UpLQr=ahvnEDeDsZMfrJ13346bzzMOjLgM=zrhtb...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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.

Thanks!

On Thu, Jan 8, 2015 at 12:26 PM, divyanshu ranjan <
[email protected]> wrote:

> Hi Dustin,
>
> (tag x) return something of type b which implements Sized and Monoid.
> Where as getSize takes value of type Size.
> Hence the error. b might not be equal to Size. Thus compiler is
> complaining.
>
> Given b is (Sized b), how one can convert it into Size ?
>
>
>
> Thanks
> Divyanshu Ranjan
>
>
> On Fri, Jan 9, 2015 at 12:31 AM, Dustin Lee <[email protected]> wrote:
>
>> 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)
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Dustin Lee
qhfgva=rot13(dustin)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150108/91433d83/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 79, Issue 12
*****************************************

Reply via email to