Skip to content

Commit

Permalink
Polish, add batching/remote execution to related work
Browse files Browse the repository at this point in the history
  • Loading branch information
snowleopard committed Mar 2, 2019
1 parent 404a598 commit 5e70b5e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 32 deletions.
14 changes: 7 additions & 7 deletions paper/2-selective.tex
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ \section{Selective functors}\label{sec-selective}
\vspace{1mm}
\begin{minted}[xleftmargin=10pt]{haskell}
selectM :: Monad f => f (Either a b) -> f (a -> b) -> f b
selectM x y = x >>= \e -> case e of Left a -> ($a) <$> y -- execute y
Right b -> pure b -- skip y
selectM x y = x >>= \e -> case e of Left a -> ($a) <$> y -- Execute y
Right b -> pure b -- Skip y
\end{minted}
\vspace{1mm}
Expand All @@ -153,7 +153,7 @@ \section{Selective functors}\label{sec-selective}
\vspace{1mm}
\begin{minted}[xleftmargin=10pt]{haskell}
selectA :: Applicative f => f (Either a b) -> f (a -> b) -> f b
selectA x y = (\e f -> either f id e) <$> x <*> y
selectA x y = (\e f -> either f id e) <$> x <*> y -- Execute x and y
\end{minted}
\vspace{1mm}

Expand Down Expand Up @@ -400,8 +400,8 @@ \subsection{Examples of selective functors}\label{sec-instances}
\begin{minted}[xleftmargin=10pt]{haskell}
-- 'mempty' and '<>' are the identity and the binary operation of the Monoid m
instance Monoid m => Applicative (Const m) where
pure _ = Const mempty -- pure values have no effects
Const x <*> Const y = Const (x <> y) -- collect effects in x and y
pure _ = Const mempty -- Pure values have no effects
Const x <*> Const y = Const (x <> y) -- Collect effects in x and y
\end{minted}
\vspace{1mm}
Expand All @@ -421,12 +421,12 @@ \subsection{Examples of selective functors}\label{sec-instances}
newtype Under m a = Under { getUnder :: m }
instance Monoid m => Selective (Over m) where
select (Over x) (Over y) = Over (x <> y) -- collect effects in x and y
select (Over x) (Over y) = Over (x <> y) -- Collect effects in x and y
\end{minted}
\vspace{1mm}
\begin{minted}[xleftmargin=10pt]{haskell}
instance Monoid m => Selective (Under m) where
select (Under x) _ = Under x -- discard conditional effects
select (Under x) _ = Under x -- Discard conditional effects
\end{minted}
\vspace{1mm}
Expand Down
2 changes: 1 addition & 1 deletion paper/5-free.tex
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ \subsection{Ping-pong, freely}\label{sec-free-ping-pong}
\vspace{1mm}
\begin{minted}[xleftmargin=10pt]{haskell}
greeting = getLine >>= \name -> putStrLn ("Hello, " ++ name)
greeting = getLine >>= \name -> putStrLn ("Hello " ++ name)
\end{minted}
\vspace{1mm}
Expand Down
13 changes: 5 additions & 8 deletions paper/6-alternatives.tex
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ \subsection{Symmetric select operators}\label{sec-alt-symmetric}
argument of \hs{select} must always be executed, while the second argument may
sometimes be skipped. Consider the following more symmetric alternative:

\vspace{1mm}
\begin{minted}[xleftmargin=5pt]{haskell}
biselect :: Selective f => f@\,@(Either a b) -> f@\,@(Either a c) -> f@\,@(Either a (b,c))
\end{minted}
\vspace{1mm}

\noindent
This definition is pleasantly symmetric: if either of the arguments yields a
Expand All @@ -102,13 +100,13 @@ \subsection{Symmetric select operators}\label{sec-alt-symmetric}
from~\S\ref{sec-laws} looks much more natural for
\hs{(?*?)}~\hs{=}~\hs{biselect}:

\vspace{1mm}
\vspace{0.5mm}
\begin{minted}[xleftmargin=10pt]{haskell}
@\blk{x}@ ?*? (y ?*? z) = second assoc <$> ((x ?*? y) ?*? z)
where
assoc ((a, b), c) = (a, (b, c))
\end{minted}
\vspace{1mm}
\vspace{0.5mm}
\noindent
While beautiful, we found \hs{biselect} to be a bit more awkward to work with
Expand All @@ -119,15 +117,14 @@ \subsection{Symmetric select operators}\label{sec-alt-symmetric}
such use-cases it is possible to add \hs{biselect} to the \hs{Selective} type
class with the following default implementation:
\vspace{1mm}
\vspace{0.5mm}
\begin{minted}[xleftmargin=5pt]{haskell}
biselect :: Selective f => f@\,@(Either a b) -> f@\,@(Either a c) -> f@\,@(Either a (b,c))
biselect x y = select ((fmap Left . swap) <$> x) ((\e a -> fmap (a,) e) <$> y)
where
swap (Left a) = Right a
swap (Right b) = Left b
swap = either Right Left -- Swap Left and Right
\end{minted}
\vspace{1mm}
\vspace{0.5mm}
\noindent
This implementation breaks the symmetry, which may be acceptable for most
Expand Down
30 changes: 17 additions & 13 deletions paper/7-related.tex
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ \section{Related work}\label{sec-related}
selective functors would give us the ability to statically analyse effectful
computations with cycles.

Our free construction for rigid selective functors is inspired by the works
on free applicative functors~\citep{free-applicatives} and free
monads~\citep{swierstra2008data}, as well as by insightful blog posts
by~\citet{fancher2016free,fancher2017static}.
Our free construction for rigid selective functors~(\S\ref{sec-free}) is
inspired by the works on free applicative functors~\citep{free-applicatives},
free monads~\citep{swierstra2008data}, and insightful blog posts
by~\citet{fancher2016free,fancher2017static}. \emph{Batching and remote
execution} of effectful computations~\citep{gill2015remote} can be greatly
simplified by using free applicative functors, as
demonstrated by~\citet{gibbons2016free}, and we believe that free selective
functors uncover new opportunities in this area.

\subsection{Arrows and profunctors}\label{sec-arrows}

Expand All @@ -37,11 +41,11 @@ \subsection{Arrows and profunctors}\label{sec-arrows}

\vspace{1mm}
\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
class Category a -- identity arrow, sequential arrow composition
class Category a => Arrow a -- pure arrows, parallel arrow composition
class Arrow a => ArrowChoice a -- arrows with choice
class Arrow a => ArrowApply a -- arrows that take arrows as input
class Arrow a => ArrowLoop a -- arrows with loops
class Category a -- Identity arrow, sequential arrow composition
class Category a => Arrow a -- Pure arrows, parallel arrow composition
class Arrow a => ArrowChoice a -- Arrows with choice
class Arrow a => ArrowApply a -- Arrows that take arrows as input
class Arrow a => ArrowLoop a -- Arrows with loops
\end{minted}
\vspace{1mm}

Expand Down Expand Up @@ -135,10 +139,10 @@ \subsection{Parsers and \hs{Alternative} type class}\label{sec-alternative-funct

\vspace{1mm}
\begin{minted}[xleftmargin=10pt]{haskell}
sat :: (Char -> Bool) -> Parser Char -- parse a specified character
string :: String -> Parser String -- parse a string literal
bin :: Parser Int -- parse a binary-encoded number
hex :: Parser Int -- parse a hexadecimal-encoded number
sat :: (Char -> Bool) -> Parser Char -- Parse a specified character
string :: String -> Parser String -- Parse a string literal
bin :: Parser Int -- Parse a binary-encoded number
hex :: Parser Int -- Parse a hexadecimal-encoded number
\end{minted}
\vspace{1mm}

Expand Down
24 changes: 23 additions & 1 deletion paper/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,26 @@ @INPROCEEDINGS{ellson2001graphviz
year = {2001},
pages = {483--484},
publisher = {Springer-Verlag}
}
}

@inproceedings{gill2015remote,
title={The remote monad design pattern},
author={Gill, Andy and Sculthorpe, Neil and Dawson, Justin and Eskilson, Aleksander and Farmer, Andrew and Grebe, Mark and Rosenbluth, Jeffrey and Scott, Ryan and Stanton, James},
booktitle={ACM SIGPLAN Notices},
volume={50},
number={12},
pages={59--70},
year={2015},
organization={ACM}
}

@inproceedings{gibbons2016free,
title={Free delivery (functional pearl)},
author={Gibbons, Jeremy},
booktitle={ACM SIGPLAN Notices},
volume={51},
number={12},
pages={45--50},
year={2016},
organization={ACM}
}
3 changes: 1 addition & 2 deletions src/Control/Selective.hs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ andAlso x y = swap <$> orElse (swap <$> x) (swap <$> y)

-- | Swap left and right.
swap :: Either a b -> Either b a
swap (Left a) = Right a
swap (Right b) = Left b
swap = either Right Left

-- | Append two semigroup values or return the @Right@ one.
appendLeft :: Semigroup a => a -> Either a b -> Either a b
Expand Down

0 comments on commit 5e70b5e

Please sign in to comment.