haskell,types,monoids,type-variables,foldable

I found that this typechecks: {-# LANGUAGE RankNTypes #-} module FoldableTA where import Control.Category import Prelude hiding (id, (.)) class FoldableTA fm where foldMapTA :: Category h => (forall b c . a b c -> h b c) -> fm a b d -> h b d foldrTA ::...

This works because of erasure. @@ is a purely type-level construct, meaning it has no runtime representation. The type A @@ T is an alias for the type AnyRef{type Tag = T; type Self = A}. And since Int can be safely cast to AnyRef (under the hood this is...

If you already have fun1, just add an instance: instance Monoid TypeA where mempty = .... -- fill this with the neutral element mappend = fun1 Probably, you want mempty = TypeA []....

haskell,io,getline,empty-string,monoids

Your thinking is excellent. Monoid is a great structure for this, but sadly as bheklilr points out, sequence is going to perform all the IO regardless. Theory vs practicality with a nod to Alternative It would be nice to make instance Monoid (IO String) but we'd have to wrap it...

I think Alt from the semigroupoids package comes closest to being a 'standard' typeclass. https://hackage.haskell.org/package/semigroupoids-5.0.0.1/docs/Data-Functor-Alt.html#t:Alt

I believe there is a deeper reason. While it seems there is no canonical set of rules for Alternative, in order for Alternative to make sense, there definitely ought to be a relationship between Alternative and its Applicative operations (otherwise it'd be just an arbitrary monoid.) This answer to Confused...

xml,haskell,arrows,hxt,monoids

It seems like you have some confusion between how the >>> and <+> operators work. To build intuition, let's first define two different bars: bar1 :: ArrowXml a => a XmlTree XmlTree bar1 = this <+> eelem "bar" bar2 :: ArrowXml a => a n XmlTree bar2 = eelem "bar"...

Nothing bad would happen in terms of type safety: Your programs will still not crash. But a data structure relying on your Monoid instance might give unexpected or wrong results. Consider a tree that is re-balanced upon insertion, and that provides a way to combine its elements using their Monoid...

You can parameterize the type in the signature. But composing monoids then becomes odd or impossible. Haskell solves this using type classes, which you can emulate in SML with functors, but the syntax is heavy (as you've noticed). signature MONOID = sig type 'a monoid val neutral : 'a monoid...

If i'm not mistaken there should be a monoid for Option, so simple def combine[T: Monoid](a: Option[T], b: Option[T]) = a |+| b should work....