Nov. 19th, 2011

WTF

Nov. 19th, 2011 05:58 pm
deniok: (Default)
из Control.Applicative (с) Conor McBride and Ross Paterson 2005
newtype Const a b = Const { getConst :: a }

instance Functor (Const m) where
    fmap _ (Const v) = Const v

instance Monoid m => Applicative (Const m) where
    pure _ = Const mempty
    Const f <*> Const v = Const (f `mappend` v)


из Data.Functor.Constant (c) Ross Paterson 2010
(transformers package)
import Control.Applicative -- Sic!

...

newtype Constant a b = Constant { getConstant :: a }

instance Functor (Constant a) where
    fmap f (Constant x) = Constant x

...

instance (Monoid a) => Applicative (Constant a) where
    pure _ = Constant mempty
    Constant x <*> Constant y = Constant (x `mappend` y)


UPD. Росс ответил в кафе, что it was an accident

Profile

deniok: (Default)
deniok

February 2022

S M T W T F S
  12345
6789101112
13141516171819
20212223 242526
2728     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 20th, 2025 03:05 pm
Powered by Dreamwidth Studios