diff options
Diffstat (limited to 'Alpha.hs')
-rw-r--r-- | Alpha.hs | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -41,6 +41,10 @@ module Alpha (</), (<//), + -- * Shoving / binding + bind, + (>>=), + -- * Bool don't, @@ -73,7 +77,8 @@ import Data.String import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Lazy as LazyText -import Protolude as X hiding (list, ($), (&), (.)) +import Protolude as X hiding (list, ($), (&), (.), (>>=)) +import qualified Prelude -- | Create a list. This should be @Data.List.singleton@ but that doesn't exist. list :: a -> [a] @@ -93,7 +98,7 @@ compose f g x = g (f x) (.>) :: (a -> b) -> (b -> c) -> (a -> c) f .> g = compose f g -infixl 9 .> +-- infixl 0 .> -- | Left-composition operator -- @@ -101,7 +106,7 @@ infixl 9 .> (<.) :: (b -> c) -> (a -> b) -> (a -> c) g <. f = compose f g -infixr 9 <. +-- infixr 0 <. -- | Alias for map, fmap, <$> -- @@ -109,6 +114,8 @@ infixr 9 <. (</) :: Functor f => (a -> b) -> f a -> f b f </ g = fmap f g +-- infixr 1 </ + -- | Double fmap. A function on the left goes "into" two functors -- (i.e. it goes "two levels deep"), applies the function to the inner -- values, then returns the result wrapped in the two functors. @@ -117,6 +124,8 @@ f </ g = fmap f g (<//) :: (Functor f0, Functor f1) => (a -> b) -> f0 (f1 a) -> f0 (f1 b) (<//) = fmap .> fmap +-- infixr 1 <// + -- | Normal function application. Do the right side, then pass the -- return value to the function on the left side. -- @@ -124,7 +133,7 @@ f </ g = fmap f g (<|) :: (a -> b) -> a -> b f <| g = f g -infixr 0 <| +infixr 1 <| -- | Reverse function application. Do the left side, then pass the -- return value to the function on the right side. @@ -143,6 +152,16 @@ infixl 1 |> (/>) :: Functor f => f a -> (a -> b) -> f b f /> g = fmap g f +infixl 1 /> + +bind :: Monad m => m a -> (a -> m b) -> m b +bind a f = a Prelude.>>= f + +(>>=) :: Monad m => m a -> (a -> m b) -> m b +a >>= b = a Prelude.>>= b + +infixl 1 >>= + -- | Removes newlines from text. chomp :: Text -> Text chomp = Text.filter (/= '\n') |