ref: 325f7f6cfde211bcdd4389e34585cee9330cc10c
parent: 8f7bd08f3e3c947ac0ec0d2787b4ff5d383d0782
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Thu Oct 26 09:30:04 EDT 2023
More modules
--- /dev/null
+++ b/lib/Control/Applicative.hs
@@ -1,0 +1,9 @@
+module Control.Applicative(module Control.Applicative) where
+import Primitives -- for fixity
+import Data.Functor
+
+infixl 4 <*>
+
+class Functor f => Applicative (f :: Type -> Type) where
+ pure :: forall a . a -> f a
+ (<*>) :: forall a b . f (a -> b) -> f a -> f b
--- /dev/null
+++ b/lib/Control/Monad.hs
@@ -1,0 +1,15 @@
+module Control.Monad(module Control.Monad) where
+import Primitives -- for fixity
+import Control.Applicative
+
+infixl 1 >>
+infixl 1 >>=
+
+class (Applicative m) => Monad (m :: Type -> Type) where
+ (>>=) :: forall a b . m a -> (a -> m b) -> m b
+ (>>) :: forall a b . m a -> m b -> m b
+
+-- ma >> mb = ma >>= \ _ -> mb
+
+return :: forall (m :: Type -> Type) a . Monad m => a -> m a
+return = pure
--- /dev/null
+++ b/lib/Data/Functor.hs
@@ -1,0 +1,12 @@
+module Data.Functor(module Data.Functor) where
+import Primitives -- for fixity
+
+class Functor (f :: Type -> Type) where
+ fmap :: forall a b . (a -> b) -> f a -> f b
+
+infixl 4 <$>
+(<$>) :: forall (f :: Type -> Type) a b . Functor f => (a -> b) -> f a -> f b
+(<$>) = fmap
+
+--void :: forall f a . Functor f => f a -> f ()
+--void = fmap (const ())
--- /dev/null
+++ b/lib/Data/Identity.hs
@@ -1,0 +1,23 @@
+module Data.Identity(Data.Identity) where
+import Primitives
+import Data.Functor
+import Control.Applicative
+import Control.Monad
+
+newtype Identity a = Identity a
+
+fm :: forall a b . (a -> b) -> Identity a -> Identity b
+fm f (Identity a) = Identity (f a)
+
+instance Functor Identity where
+ fmap :: forall a b . (a -> b) -> Identity a -> Identity b
+ fmap f (Identity a) = Identity (f a)
+
+{-+instance Applicative Identity where
+ pure a = Identity a
+ Identity f <*> Identity a = Identity (f a)
+
+instance Monad Identity where
+ Identity a >>= f = f a
+-}
--
⑨