-
-
Save klapaucius/3046698 to your computer and use it in GitHub Desktop.
XDefaultSignatures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude Control.Monad> :set -XDefaultSignatures | |
Prelude Control.Monad> | |
newtype Box a = Box a deriving Show | |
Prelude Control.Monad> | |
instance Monad Box where | |
return = Box | |
(Box x) >>= f = f x | |
Prelude Control.Monad> join (Box (Box 2)) | |
Box 2 | |
Prelude Control.Monad> | |
class DFunctor f where | |
dmap :: (a -> b) -> f a -> f b | |
default dmap :: Monad f => (a -> b) -> f a -> f b | |
dmap f = ((return . f) =<<) | |
Prelude Control.Monad> | |
instance DFunctor Box | |
Prelude Control.Monad> dmap (+1) $ Box 2 | |
Box 3 | |
Prelude Control.Monad> | |
class DApplicative f where | |
dpure :: a -> f a | |
default dpure :: Monad f => a -> f a | |
dpure = return | |
dap :: f (a -> b) -> f a -> f b | |
default dap :: Monad f => f (a -> b) -> f a -> f b | |
dap = ap | |
Prelude Control.Monad> | |
instance DApplicative Box | |
Prelude Control.Monad> dpure (+) `dap` Box 2 `dap` Box 3 | |
Box 5 | |
Prelude Control.Monad> | |
newtype Xob a = Xob a deriving Show | |
Prelude Control.Monad> | |
instance DFunctor Xob where | |
dmap f (Xob a) = Xob . f $ a | |
Prelude Control.Monad> dmap (+1) . Xob $ 41 | |
Xob 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude> | |
class DMonad m where | |
djoin :: m(m a) -> m a | |
djoin = dbind id | |
dbind :: (a -> m b) -> m a -> m b | |
default dbind :: DFunctor m => (a -> m b) -> m a -> m b | |
dbind f = djoin . dmap f | |
dreturn :: a -> m a | |
default dreturn :: DApplicative m => a -> m a | |
dreturn = dpure | |
class DFunctor f where | |
dmap :: (a -> b) -> f a -> f b | |
default dmap :: DMonad f => (a -> b) -> f a -> f b | |
dmap f = dbind (dreturn . f) | |
class DApplicative f where | |
dpure :: a -> f a | |
default dpure :: DMonad f => a -> f a | |
dpure = dreturn | |
dap :: f (a -> b) -> f a -> f b | |
default dap :: DMonad f => f (a -> b) -> f a -> f b | |
dap = undefined | |
Prelude> instance DApplicative [] where | |
dpure x = [x] | |
dap = Control.Monad.ap | |
Prelude> instance DFunctor [] where | |
dmap = map | |
Prelude> instance DMonad [] where | |
djoin = concat | |
Prelude> dbind (\x -> [x,x]) [1..3] | |
[1,1,2,2,3,3] | |
Prelude> dbind dreturn [1..3] | |
[1,2,3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude Control.Monad Data.Traversable Data.Foldable Control.Applicative> | |
class DTFunctor f where | |
tmap :: (a -> b) -> f a -> f b | |
default tmap :: Monad f => (a -> b) -> f a -> f b | |
tmap f = ((return . f) =<<) | |
default tmap :: Traversable f => (a -> b) -> f a -> f b | |
tmap = fmapDefault | |
<interactive>:102:5: | |
Duplicate default type signature: | |
<interactive>:102:5-53: default tmap :: | |
Monad f => (a -> b) -> f a -> f b | |
<interactive>:104:5-59: default tmap :: | |
Traversable f => (a -> b) -> f a -> f b | |
<interactive>:103:5: | |
Conflicting definitions for `tmap' | |
Bound at: <interactive>:103:5-8 | |
<interactive>:105:5-8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment