[Haskell-beginners] Example using gmapQ

Adrian May adrian.alexander.may at gmail.com
Sat Jul 13 13:56:47 CEST 2013


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 <dilawars at iitb.ac.in> 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
>> Beginners at haskell.org
>> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>>
>
>
> ______________________________**_________________
> Beginners mailing list
> Beginners at haskell.org
> 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.htm>


More information about the Beginners mailing list