[Haskell-cafe] Re: Polyvariadic functions operating with a monoid

Brandon S Allbery KF8NH allbery at ece.cmu.edu
Sat Oct 9 17:51:24 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/9/10 10:25 , Kevin Jardine wrote:
> instance Show a => Monoidable a [String] where
>     toMonoid a = [show a]
> 
> main = putStrLn $ unwrap $ polyToMonoid [] True () (Just (5::Int))
> 
> fails to compile.
> 
> Why would that be? My understanding is that all lists are
> automatically monoids.

I *think* the problem here is that Oleg specifically pointed out that the
first parameter to polyToMonoid must specify the type of the monoid.  []
tells you it's a list, therefore a monoid, but it doesn't say enough to
allow the [String] instance to be chosen.  (No, the fact that you only
declared an instance for [String] isn't really enough.)

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allbery at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyw49wACgkQIn7hlCsL25VZygCfVETk+3AZ3gKoBy4pZ7j8g4Km
WXgAnjrbO9rEl2HnQtGQ31EyRuhWzI4r
=YMDw
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list