sorry folks… it’s been too long. i’m back with you again after a long break from blog world. i’ll try to keep you up to date for the remaining pavement shows. this weekend, we’re in montreal for the osheaga festival. next weekend we are in japan, and… Continua a leggere
Take (or imagine) a blank sheet of paper. This is a plane. You can put points and vectors on it. A vector connects two points, but it is “movable”: if you can translate one vector into another, they are deemed equal. A vector doesn’t really have a begi… Continua a leggere
Ultrecht Haskell Compiler is an experimental Haskell compiler that supports polymorphism on the kind level. This means that in
data Eq a b = Eq (forall f. f a -> f b)
Eq is given kind
Eq :: forall a . a -> a -> *
and both Eq Integer Char and Eq  Maybe are valid types.
Using kind polymorphism, it is possible to write sigfpe’s From monoids to monads using a single type class.
To talk about monoids, you need a category (mor), multiplication (mul) and a unit.
class Monoid mor mul unit m where
one :: mor unit m
mult :: mor (mul m m) m
With mor being (->), mul being (,), unit being () this is a normal monoid (one :: () -> m and mult :: (m,m) -> m.). For example:
instance Monoid (->) (,) () Integer where
one () = 1
mult = uncurry (*)
Now, instead of functions, there will be natural transformations; instead of (,) there will be functor composition; instead of unit there will be identity functor.
data Nat f g = Nat (forall x. f x -> g x)
data Comp f g x = Comp (f (g x))
data Id x = Id x
Nat :: (* -> *) -> (* -> *) -> *
Comp :: (* -> *) -> (* -> *) -> * -> *
Id :: * -> *
And here is the list monad. Notice kinds are different than in the previous case, but it is still an instance of the same type class.
instance Monoid Nat Comp Id  where
one = Nat $ \(Id x) -> [x] -- one :: Nat Id 
mult = Nat $ \(Comp x) -> concat x -- mult :: Nat (Comp  ) 
So, monads are really monoids in category of endofunctors.
If you invert the arrows, you get a comonad. Here’s the product comonad.
data CoNat f g = CoNat (forall x. g x -> f x)
data CoComp f g x = CoComp (g (f x))
CoNat :: (* -> *) -> (* -> *) -> *
CoComp :: (* -> *) -> (* -> *) -> * -> *
data Product w a = Product w a
instance Monoid CoNat CoComp Id (Product w) where
one = CoNat $ \(Product a b) -> Id b
mult = CoNat $ \(Product a b) -> CoComp $ Product a (Product a b)
Question: what are kinds of mor, mul, unit and m in the Monoid type class definition?
There’s a small lie here: monads require also a liftM/fmap function. Not all Haskell types of * -> * are functors, and I used that as a poor replacement.
I didn’t write monoid laws, which if translated happen to be monad laws. You’re welcome to read sigfpe’s original post. It’s hard to write them generically since there’s no access to fmap.
Yup, fixed it. Home PC is back online. Got some major catching up to do now to get the final 40k video up and running then I’m in the clear with you guys – right?? I hope so ! Then its just a case of “what next” Continua a leggere
Von 26.7.2010 bis 6.8.2010 hat Firma ALU.PLAST s.r.o. firmen Urlaub
Während der Urlaub rufen Sie bitte an
Handy : +420 603/544 049 Continua a leggere
Marvell WA-T2.I hate that little make and model number above because I’ve been googling my brains out trying to find a windows 7 64 bit driver for that archaic wireless card for ages. It is not supported so I’ve had to buy a new one which will be with… Continua a leggere
Numerous authorities link nitrosamines to cancer. They are listed as possible human carcinogens by the EPA, the International Agency for Research on Cancer, the U.S. National Toxicology Program Report on Carcinogens and the California EPA Propositio… Continua a leggere
Formaldehyde, most commonly associated with embalming fluid, is a known carcinogen. Its highly toxic nature makes it an effective preservative in cosmetics, too. While it’s not typically listed in an ingredients list on its own, a number of preservat… Continua a leggere