From 9f9dcf54c3adb45012dd01dfd8137764046c968f Mon Sep 17 00:00:00 2001
From: Ben Sima <ben@bsima.me>
Date: Fri, 27 Mar 2020 12:07:16 -0700
Subject: Add onomatopoeitic operators

It's easier to remember what operators do, and thus easier to write and
read condens code, if they follow some symbolic pattern or visually
represent the concept to which they map. This is in part inspired by
hoon, in part by OCaml's operators.

I'm not married to these operators specifically, but I think they are
good so far.
---
 Com/Simatime/Alpha.hs | 54 ++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 43 insertions(+), 11 deletions(-)

(limited to 'Com/Simatime/Alpha.hs')

diff --git a/Com/Simatime/Alpha.hs b/Com/Simatime/Alpha.hs
index 16d21e3..8f5a506 100644
--- a/Com/Simatime/Alpha.hs
+++ b/Com/Simatime/Alpha.hs
@@ -4,9 +4,13 @@ module Com.Simatime.Alpha
   (
   -- * Re-export Protolude
     module X
-  -- * General functions
-  , (/@)
-  , (/@@)
+  -- * Applying
+  , (<|)
+  , (|>)
+  -- * Mapping
+  , (/>)
+  , (</)
+  , (<//)
   -- * Debugging tools
   , say
   -- * TODO: remove this
@@ -14,20 +18,48 @@ module Com.Simatime.Alpha
   )
 where
 
+import           Data.Function                  ( (&) )
+import           Data.Functor                   ( (<&>) )
+import           Data.String
 import           Data.Text                      ( Text )
 import qualified Prelude
 import           Protolude                     as X
-import           Data.String
 
 -- | Debugging printf
 say :: Text -> IO ()
 say msg = putStrLn msg
 
--- | Alias for map, fmap, <$>. Inspired by Mathematica.
-(/@) :: Functor f => (a -> b) -> f a -> f b
-(/@) = fmap
+-- $operators
+--
+-- Operators have a pattern to their characters
+--
+-- `|` normal function-level applications
+-- `/` indicates doing something inside a functor
+-- `<` and `>` indicate the direction in which values flow btw functions
+
+-- | Alias for map, fmap, <$>
+(</) :: Functor f => (a -> b) -> f a -> f b
+(</) = fmap
+
+-- | 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.
+(<//) :: (Functor f0, Functor f1) => (a -> b) -> f0 (f1 a) -> f0 (f1 b)
+(<//) = fmap . fmap
+
+-- | Normal function application. Do the right side, then pass the
+-- return value to the function on the left side.
+(<|) :: (a -> b) -> a -> b
+(<|) = ($)
+infixr 0 <|
+
+-- | Reverse function application. Do the left side, then pass the
+-- return value to the function on the right side.
+(|>) :: a -> (a -> b) -> b
+(|>) = (&)
 
--- | Double fmap.
--- (/@@) :: (Functor f1, Functor f2) => f1 (a -> b) -> f1 (f2 a) -> f1 (f2 b)
-(/@@) :: (Functor f0, Functor f1) => (a -> b) -> f0 (f1 a) -> f0 (f1 b)
-(/@@) = fmap . fmap
+-- | Alias for <&>. Can be read as "and then". Basically does into a
+-- functor, does some computation, then returns the same kind of
+-- functor. Could also be defined as `f >>= return . g`
+(/>) :: Functor f => f a -> (a -> b) -> f b
+(/>) = (<&>)
-- 
cgit v1.2.3