Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proc desugaring PSA #153

Open
cfhammill opened this issue Nov 21, 2019 · 1 comment
Open

Proc desugaring PSA #153

cfhammill opened this issue Nov 21, 2019 · 1 comment

Comments

@cfhammill
Copy link

The proc notation introduced by the Arrows language extension desugars in a very inefficient way, adding many irrelevant steps to the computation graph. A simple example, here a is the proc version and b is the point-free variant

{-# LANGUAGE Arrows, OverloadedStrings #-}
import Control.Funflow
import Control.Funflow.Pretty
import Path
import Data.Default

a :: SimpleFlow (Path a Dir) (String)
a = proc d -> do
  stepIO' (def {name = Just "reading file"}) (readFile . toFilePath) -< d

b :: SimpleFlow (Path a Dir) (String)
b = stepIO' (def {name = Just "reading file"}) (readFile . toFilePath)

print $ ppFlow a
print $ ppFlow b

Which outputs

-- a
(unlabeled step >>> (unlabeled step >>> (unlabeled step >>> (unlabeled step >>> reading file))))
-- b
reading file

There is a library arrowp-qq that provides a quasiquoter version of the proc notation that does a better job of desugaring

{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Control.Arrow.QuasiQuoter

c :: SimpleFlow (Path a Dir) (String)
c =  [proc| d -> do
              stepIO' (def {name = Just "reading file"}) (readFile . toFilePath) -< d
              |]

print $ ppFlow c
(unlabeled step >>> reading file)

unfortunately the package hasn't been actively developed recently, so I had to modify it slightly to get it work.

For rendering workflows as graphs, using something like the quasiquoter proc notation may be useful for generating human readable graphs.

@dorranh
Copy link
Contributor

dorranh commented Jul 22, 2021

I'm actually not sure if this issue is addressed now that we are using kernmantle's Rope to represent flows in funflow2, and it is worth investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants