[Haskell-beginners] Bit confused...

mike h mike_k_houghton at yahoo.co.uk
Sat Feb 4 08:13:09 UTC 2017


Yes, that’s exactly what I meant to write!!! :)
Thank you Francesco.

Mike

> On 3 Feb 2017, at 21:59, Francesco Ariis <fa-ml at ariis.it> wrote:
> 
> On Fri, Feb 03, 2017 at 09:47:04PM +0000, mike h wrote:
>> I have 
>> 
>> ----------
>> import qualified Data.Map as M
>> 
>> type Link a = (a, Int)
>> data MChain a = Map a   [Link a]  deriving (Show)
>> 
>> -------------------
>> 
>> and want to make a Monoid of MChain. So I have
>> 
>> -------------------
>> instance Monoid (MChain a) where
>>   mempty = M.empty 
>>   mappend = undefined
>> -------------------
>> 
>> this won’t compile and I need M.empty to be Map a   [Link a] 
> 
> Hello Mike, I think the error lies in the confusion between
> `type` and `data` declaration.
> 
>    type Something = Int
> 
> but
> 
>    data Something = SomeConstructor Int
> 
> So I bet you wanted to write
> 
>    data MChain a = MChain (M.Map a [Link a]) deriving (Show)
> 
> `M.empty` returns a Map.
> 
>    λ> :t M.empty
>    M.empty :: M.Map k aj
> 
> Hence this will work:
> 
>    instance Monoid (MChain a) where
>       mempty = MChain M.empty
>       mappend = undefined
> 
> Does this help?
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org <mailto:Beginners at haskell.org>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170204/77e6a737/attachment-0001.html>


More information about the Beginners mailing list