From 9f9dcf54c3adb45012dd01dfd8137764046c968f Mon Sep 17 00:00:00 2001 From: Ben Sima 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/InfluencedByBooks/Core.hs | 4 +-- Com/InfluencedByBooks/Move.hs | 4 +-- Com/MusicMeetsComics/App.hs | 6 ++-- Com/MusicMeetsComics/Look/Typography.hs | 2 +- Com/Simatime/Alpha.hs | 54 ++++++++++++++++++++++++++------- 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Com/InfluencedByBooks/Core.hs b/Com/InfluencedByBooks/Core.hs index 1a8bf6f..6984004 100644 --- a/Com/InfluencedByBooks/Core.hs +++ b/Com/InfluencedByBooks/Core.hs @@ -100,7 +100,7 @@ see m = div_ [ class_ "container mt-5" ] NotAsked -> [ text "Initializing..." ] Loading -> [ text "Loading..." ] Failure err -> [ text err ] - Success ps -> seePerson /@ ps + Success ps -> seePerson View Action @@ -115,7 +115,7 @@ seePerson person = div_ [ class_ "card" ] ] , p_ [ class_ "card-text" ] [ text $ ms $ _blurb person - , ul_ [] $ seeBook /@ _books person + , ul_ [] $ seeBook Model -> Effect Action Model move Nop m = noEff m move (HandleRoute u) m = m { uri = u } <# pure Nop move (ChangeRoute u) m = m <# do pushURI u >> pure Nop -move FetchPeople m = m <# (SetPeople /@ fetchPeople) +move FetchPeople m = m <# (SetPeople pure $ Failure "could not read from server" Just a -> pure diff --git a/Com/MusicMeetsComics/App.hs b/Com/MusicMeetsComics/App.hs index 7f5b47f..fa3b8e9 100644 --- a/Com/MusicMeetsComics/App.hs +++ b/Com/MusicMeetsComics/App.hs @@ -408,7 +408,7 @@ mediaInfo Nothing _ = text "" mediaInfo (Just comic) lib = div_ [ class_ "media-info" ] [ info comic lib ] appmenu :: View Action -appmenu = aside_ [ id_ "appmenu" ] $ btn /@ links +appmenu = aside_ [ id_ "appmenu" ] $ btn MisoString -> [o] -> View Action shelf title comics = div_ [ class_ "shelf" ] [ div_ [ class_ "shelf-head" ] [ text title ] - , ul_ [ class_ "shelf-body" ] $ thumbnail /@ comics + , ul_ [ class_ "shelf-body" ] $ thumbnail "/old-assets/fonts/eurostile/Eurostile" fonts :: Css -fonts = mconcat $ mkEuro /@ +fonts = mconcat $ mkEuro fontStyle normal) , ("LTStd-Bold.otf", OpenType, thicc <> norm) , ("LTStd-Cn.otf", OpenType, slim <> norm) 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 + , (/>) + , () ) +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, <$> +( (a -> b) -> f a -> f b +( (a -> b) -> f0 (f1 a) -> f0 (f1 b) +( 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