[Haskell-cafe] Re: Polyvariadic functions operating with a monoid
Kevin Jardine
kevinjardine at gmail.com
Sat Oct 9 10:39:33 EDT 2010
Another example that also fails to compile (but I cannot see why):
import Data.PolyToMonoid
import Data.Monoid
instance Monoid Int where
mappend = (+)
mempty = 0
instance Monoidable Int Int where
toMonoid = id
main = putStrLn $ show $ unwrap $ polyToMonoid (0::Int) (1::Int)
(2::Int) (3::Int)
In this case, I was expecting a sumOf function.
This gives me:
No instance for (PolyVariadic Int (WMonoid m))
arising from a use of `polyToMonoid'
Any further suggestions?
On Oct 9, 4:25 pm, Kevin Jardine <kevinjard... at gmail.com> wrote:
> Oleg,
>
> Another puzzle is that:
>
> instance Show a => Monoidable a String where
> toMonoid a = show a
>
> main = putStrLn $ unwrap $ polyToMonoid "" True () (Just (5::Int))
>
> works just fine, but
>
> 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.
>
> Kevin
>
> On Oct 9, 2:28 pm, Kevin Jardine <kevinjard... at gmail.com> wrote:
>
> > Hi Bartek,
>
> > Yes, it compiles, but when I try to use polyToMonoid', it turns out
> > that this function is no longer polyvariadic, unlike the original
> > polyToMonoid .
>
> > This may be what Luke meant when he wrote "you lose composability".
>
> > Even with the extra unwrap function I think that this is pretty cool,
> > but I would ideally like to hide the unwrap.
>
> > Kevin
>
> > On Oct 9, 1:50 pm, Bartek Æwik³owski <paczesi... at gmail.com> wrote:
>
> > > Hello Kevin,
>
> > > 2010/10/9 Kevin Jardine <kevinjard... at gmail.com>:
>
> > > > I was attempting to turn this into a small library and wanted to avoid
> > > > exporting unwrap.
>
> > > > I defined:
>
> > > > polyToMonoid' = unwrap . polyToMonoid
>
> > > If you disable MonomorphismRestriction this definition typechecks just
> > > fine. Alternatively, you can ask ghci about the type of "unwrap .
> > > polyToMonoid" and paste that into the type sig.
>
> > > regards,
> > > Bartek Æwik³owski
> > > _______________________________________________
> > > Haskell-Cafe mailing list
> > > Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
>
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list