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. Re:  Example using gmapQ (Dilawar Singh)
   2. Re:  cps in yaht (Dilawar Singh)
   3. Re:  Example using gmapQ (Adrian May)
   4. Re:  cps in yaht (Kim-Ee Yeoh)
   5. Re:  coding style: instead of let, return? (Kim-Ee Yeoh)
   6. Re:  cps in yaht (Deng Wu)


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

Message: 1
Date: Sat, 13 Jul 2013 16:57:35 +0530
From: Dilawar Singh <[email protected]>
Subject: Re: [Haskell-beginners] Example using gmapQ
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID: <20130713112735.GA23896@imaps://imap.iitb.ac.in>
Content-Type: text/plain; charset=us-ascii; format=flowed

Comment out the last line (main = etc...) and do this in ghci,
   :t (show thing)

Type of (show thing) is String. This is input to gmapQ function which has
following type.

   :t gmapQ 
   gmapQ :: Data a => (forall d. Data d => d -> u) -> a -> [u]

First argument to this function has the type (d -> u). Surely, this can't be 
String.

--
Dilawar 
EE, IITB 

On Sat, Jul 13, 2013 at 04:48:49PM +0800, Adrian May wrote:
>Hi All,
>
>I got this far:
>
>{-# LANGUAGE OverloadedStrings #-}
>{-# LANGUAGE DeriveDataTypeable #-}
>import Data.Text
>import Data.Typeable
>import Data.Data
>
>data Thing = Thing { foo :: Int, bar :: String}
>   deriving (Read, Show, Typeable, Data)
>thing :: Thing
>thing = Thing 1 "wop"
>con = toConstr thing
>fields = constrFields con
>main = putStrLn $ show con ++ show fields ++ ( Prelude.concat $ gmapQ show
>thing )
>
>But it's barfing like this:
>
>    Could not deduce (Show d) arising from a use of `show'
>    from the context (Data d)
>      bound by a type expected by the context: Data d => d -> [Char]
>      at w.hs:76:65-80
>
>I can see why, but not how to fix it.
>
>Any help much appreciated,
>Adrian.

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




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

Message: 2
Date: Sat, 13 Jul 2013 17:11:56 +0530
From: Dilawar Singh <[email protected]>
Subject: Re: [Haskell-beginners] cps in yaht
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID: <20130713114156.GB23896@imaps://imap.iitb.ac.in>
Content-Type: text/plain; charset=utf-8; format=flowed

>cfold? f z [] = z
>cfold? f z (x:xs) = f x z (\y -> cfold? f y xs)
>cfold (+) 0 []
>So my question comes, is it a bug in the book or something I miss here?

This can't be correct. In expression `f x z (\y ...)`, function 'f' takes three
argument but (+) can only take two. May be you are suppose to pass some other
function to cfold'.

--
Dilawar 
EE, IITB



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

Message: 3
Date: Sat, 13 Jul 2013 19:56:47 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Example using gmapQ
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cad-ubzep0jcyacqgfdh-f2ce-kutqh_gnmhxie0+05g1exw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Well I meant it as (gmapQ show) thing and in the meantime I found out that
I need to replace show with gshow, and AFAICT, type classes are
incompatible with generic stuff.

Adrian.



On 13 July 2013 19:27, Dilawar Singh <[email protected]> wrote:

> Comment out the last line (main = etc...) and do this in ghci,
>   :t (show thing)
>
> Type of (show thing) is String. This is input to gmapQ function which has
> following type.
>
>   :t gmapQ   gmapQ :: Data a => (forall d. Data d => d -> u) -> a -> [u]
>
> First argument to this function has the type (d -> u). Surely, this can't
> be String.
>
> --
> Dilawar EE, IITB
> On Sat, Jul 13, 2013 at 04:48:49PM +0800, Adrian May wrote:
>
>> Hi All,
>>
>> I got this far:
>>
>> {-# LANGUAGE OverloadedStrings #-}
>> {-# LANGUAGE DeriveDataTypeable #-}
>> import Data.Text
>> import Data.Typeable
>> import Data.Data
>>
>> data Thing = Thing { foo :: Int, bar :: String}
>>   deriving (Read, Show, Typeable, Data)
>> thing :: Thing
>> thing = Thing 1 "wop"
>> con = toConstr thing
>> fields = constrFields con
>> main = putStrLn $ show con ++ show fields ++ ( Prelude.concat $ gmapQ show
>> thing )
>>
>> But it's barfing like this:
>>
>>    Could not deduce (Show d) arising from a use of `show'
>>    from the context (Data d)
>>      bound by a type expected by the context: Data d => d -> [Char]
>>      at w.hs:76:65-80
>>
>> I can see why, but not how to fix it.
>>
>> Any help much appreciated,
>> Adrian.
>>
>
>  ______________________________**_________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>>
>
>
> ______________________________**_________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130713/c5bae27a/attachment-0001.htm>

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

Message: 4
Date: Sat, 13 Jul 2013 20:46:00 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] cps in yaht
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAPY+ZdQD7Q7ys+eZQBHUe4K4qUmh=Y1sV5Xfq47f3LrWv4H=t...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"

On Sat, Jul 13, 2013 at 4:47 PM, Deng Wu <[email protected]> wrote:

> cfold? f z (x:xs) = f x z (\y -> cfold? f y xs)
>
> and gives the test result:
>
> CPS> cfold (+) 0 [1,2,3,4]
>

The apostrophe matters!

Functions cfold and cfold' (read: see-fold prime) are two different
functions, for which you gave the definition of one but not the other.

To clear up your confusion, try giving the type signatures for both.
Daume's text is normally pretty good about this but the section on cfold
falls down in this regard.

Let me do the cfold one for you:

cfold :: (a -> r -> r) -> r -> [a] -> r

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130713/3e2accad/attachment-0001.htm>

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

Message: 5
Date: Sat, 13 Jul 2013 21:29:47 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] coding style: instead of let, return?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAPY+ZdRoM5Z+Z7v7s18=JgRKbczDs2aW7gPUvnVn=rj0rbv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Sat, Jul 13, 2013 at 1:56 PM, Obscaenvs <[email protected]> wrote:

> `
>   let p1 <- mkName "p1"
>   a <- newName "a"
> `
> , we use
> `
>   p1 <- return $ mkName "p1"
>   a <- newName "a"
> `.
>

The first case should start "let p1 = mkName ...".

The reason to avoid the second case is to avoid unnecessary function
applications. Predicating on a bona fide monad (can't be too careful these
days), the second is equivalent to the first because of the unit law.

(This being the beginners list, I should point out that it's pretty
important to learn how to desugar do notation in one's head. Normally,
reading lots of haskell code is enough to pick up that skill
subconsciously.)

You might try re-asking the question on cafe if you're really interested in
surveying this.

Personally, I'd start asking questions about code provenance when I see the
second case.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130713/6a1588e0/attachment-0001.htm>

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

Message: 6
Date: Sat, 13 Jul 2013 23:01:43 +0800
From: Deng Wu <[email protected]>
Subject: Re: [Haskell-beginners] cps in yaht
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CALeUGJyrWiC6B6VPkgQH30t0-=wk-mt_v2rrgnpknqdaiqe...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"

You're right! I neglected that there is a apostrophe, I should have been
more careful. Thanks for your help!

Regards!
-
wudeng


On Sat, Jul 13, 2013 at 9:46 PM, Kim-Ee Yeoh <[email protected]> wrote:

>
> On Sat, Jul 13, 2013 at 4:47 PM, Deng Wu <[email protected]> wrote:
>
>> cfold? f z (x:xs) = f x z (\y -> cfold? f y xs)
>>
>> and gives the test result:
>>
>> CPS> cfold (+) 0 [1,2,3,4]
>>
>
> The apostrophe matters!
>
> Functions cfold and cfold' (read: see-fold prime) are two different
> functions, for which you gave the definition of one but not the other.
>
> To clear up your confusion, try giving the type signatures for both.
> Daume's text is normally pretty good about this but the section on cfold
> falls down in this regard.
>
> Let me do the cfold one for you:
>
> cfold :: (a -> r -> r) -> r -> [a] -> r
>
> -- Kim-Ee
>
> _______________________________________________
> 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/20130713/e0c74a04/attachment.htm>

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

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


End of Beginners Digest, Vol 61, Issue 16
*****************************************

Reply via email to