Skip to content

Faster implementation for Free #104

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2affcde
Update benchmarks for 5.2.0
thomashoneyman Oct 11, 2020
2b7ad1b
Add benchmarks build to Travis
thomashoneyman Oct 11, 2020
6f520ae
Fix typos
thomashoneyman Oct 11, 2020
51dc8ee
benchmarks -> benchmark
thomashoneyman Oct 11, 2020
1e9eff6
Update README and commits.
thomashoneyman Oct 11, 2020
3bf25fa
Move existing implementation to Compat modules
thomashoneyman Oct 11, 2020
0268ccc
Add Free and Trampoline
thomashoneyman Oct 11, 2020
1a2fe6a
hoistFree -> hoist
thomashoneyman Oct 11, 2020
56c4f64
Update tests
thomashoneyman Oct 11, 2020
e32ed83
Update benchmarks
thomashoneyman Oct 11, 2020
f4bf6bd
Add Cofree and Free class
thomashoneyman Oct 11, 2020
aad58a3
Restrict exports from Control.Monad.Free
thomashoneyman Oct 11, 2020
bed6eee
Don't export view or uncons
thomashoneyman Oct 11, 2020
1a92ae8
re-add compat module for cofree
thomashoneyman Oct 11, 2020
8fb9d44
Don't import constructors from Free in Trampoline
thomashoneyman Oct 11, 2020
7e832f5
Merge branch 'master' into free-update
th-awake Oct 18, 2020
6180532
Trim compat modules by relying on new implementations
thomashoneyman Oct 18, 2020
9377e08
Re-add doc comments and instances
thomashoneyman Oct 18, 2020
b26273e
Missing doc comment on resume
thomashoneyman Oct 18, 2020
69f851b
runPure -> run
thomashoneyman Oct 18, 2020
56d6104
runPure -> run
thomashoneyman Oct 18, 2020
a100419
doc comment for free
thomashoneyman Oct 18, 2020
94f4e5f
Revert name changes and preserve existing API
thomashoneyman Oct 22, 2020
bf6718e
Fix benchmarks
thomashoneyman Oct 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions benchmark/Benchmark/Free.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Benchmark.Free (module Control.Monad.Free) where

import Control.Monad.Free
102 changes: 66 additions & 36 deletions benchmark/Benchmark/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module Benchmark.Main (main) where

import Prelude

import Benchmark.Free as Free
import Benchmark.Freef686f5f as Freef686f5f
import Benchmark.Trampoline as Trampoline
import Benchmark.Trampoline0df59c5 as Trampoline0df59c5
import Benchmark.Trampolinef686f5f as Trampolinef686f5f
import Benchotron.Core (Benchmark, benchFn, mkBenchmark)
Expand Down Expand Up @@ -30,25 +32,32 @@ leftBindSmallBenchmark =
, inputsPerSize: inputsPerSize
, gen: \n -> vectorOf n (pure 0.0)
, functions:
[ benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds)
, benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< bindsT)
[ benchFn "Free (master)" (Trampoline.runTrampoline <<< binds)
, benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds_5_2_0)
, benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< binds_0_6_1)
]
}
where
inputsPerSize :: Int
inputsPerSize = 100

binds :: Array Number -> Trampolinef686f5f.Trampoline Number
binds :: Array Number -> Trampoline.Trampoline Number
binds as = foldl (\b a -> b >>= const (gen a)) (gen 0.0) as

gen :: forall a. a -> Trampolinef686f5f.Trampoline a
gen = Freef686f5f.suspendF <<< Trampolinef686f5f.done
gen :: forall a. a -> Trampoline.Trampoline a
gen = Free.suspendF <<< Trampoline.done

bindsT :: Array Number -> Trampoline0df59c5.Trampoline Number
bindsT as = foldl (\b a -> b >>= const (genT a)) (genT 0.0) as
binds_5_2_0 :: Array Number -> Trampolinef686f5f.Trampoline Number
binds_5_2_0 as = foldl (\b a -> b >>= const (gen_5_2_0 a)) (gen_5_2_0 0.0) as

genT :: forall a. a -> Trampoline0df59c5.Trampoline a
genT = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done
gen_5_2_0 :: forall a. a -> Trampolinef686f5f.Trampoline a
gen_5_2_0 = Freef686f5f.suspendF <<< Trampolinef686f5f.done

binds_0_6_1 :: Array Number -> Trampoline0df59c5.Trampoline Number
binds_0_6_1 as = foldl (\b a -> b >>= const (gen_0_6_1 a)) (gen_0_6_1 0.0) as

gen_0_6_1 :: forall a. a -> Trampoline0df59c5.Trampoline a
gen_0_6_1 = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done

rightBindSmallBenchmark :: Benchmark
rightBindSmallBenchmark =
Expand All @@ -60,25 +69,32 @@ rightBindSmallBenchmark =
, inputsPerSize: inputsPerSize
, gen: \n -> vectorOf n (pure 0.0)
, functions:
[ benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds)
, benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< bindsT)
[ benchFn "Free (master)" (Trampoline.runTrampoline <<< binds)
, benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds_5_2_0)
, benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< binds_0_6_1)
]
}
where
inputsPerSize :: Int
inputsPerSize = 100

binds :: Array Number -> Trampolinef686f5f.Trampoline Number
binds :: Array Number -> Trampoline.Trampoline Number
binds as = foldl (\b a -> gen a >>= const b) (gen 0.0) as

gen :: forall a. a -> Trampolinef686f5f.Trampoline a
gen = Freef686f5f.suspendF <<< Trampolinef686f5f.done
gen :: forall a. a -> Trampoline.Trampoline a
gen = Free.suspendF <<< Trampoline.done

binds_5_2_0 :: Array Number -> Trampolinef686f5f.Trampoline Number
binds_5_2_0 as = foldl (\b a -> gen_5_2_0 a >>= const b) (gen_5_2_0 0.0) as

gen_5_2_0 :: forall a. a -> Trampolinef686f5f.Trampoline a
gen_5_2_0 = Freef686f5f.suspendF <<< Trampolinef686f5f.done

bindsT :: Array Number -> Trampoline0df59c5.Trampoline Number
bindsT as = foldl (\b a -> genT a >>= const b) (genT 0.0) as
binds_0_6_1 :: Array Number -> Trampoline0df59c5.Trampoline Number
binds_0_6_1 as = foldl (\b a -> gen_0_6_1 a >>= const b) (gen_0_6_1 0.0) as

genT :: forall a. a -> Trampoline0df59c5.Trampoline a
genT = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done
gen_0_6_1 :: forall a. a -> Trampoline0df59c5.Trampoline a
gen_0_6_1 = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done

leftBindLargeBenchmark :: Benchmark
leftBindLargeBenchmark =
Expand All @@ -90,26 +106,33 @@ leftBindLargeBenchmark =
, inputsPerSize: inputsPerSize
, gen: \n -> vectorOf n (pure 0.0)
, functions:
[ benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds)
[ benchFn "Free (master)" (Trampoline.runTrampoline <<< binds)
, benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds_5_2_0)
-- Disabled due to stack overflow
-- , benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< bindsT)
-- , benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< binds_0_6_1)
]
}
where
inputsPerSize :: Int
inputsPerSize = 1

binds :: Array Number -> Trampolinef686f5f.Trampoline Number
binds :: Array Number -> Trampoline.Trampoline Number
binds as = foldl (\b a -> b >>= const (gen a)) (gen 0.0) as

gen :: forall a. a -> Trampolinef686f5f.Trampoline a
gen = Freef686f5f.suspendF <<< Trampolinef686f5f.done
gen :: forall a. a -> Trampoline.Trampoline a
gen = Free.suspendF <<< Trampoline.done

bindsT :: Array Number -> Trampoline0df59c5.Trampoline Number
bindsT as = foldl (\b a -> b >>= const (genT a)) (genT 0.0) as
binds_5_2_0 :: Array Number -> Trampolinef686f5f.Trampoline Number
binds_5_2_0 as = foldl (\b a -> b >>= const (gen_5_2_0 a)) (gen_5_2_0 0.0) as

genT :: forall a. a -> Trampoline0df59c5.Trampoline a
genT = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done
gen_5_2_0 :: forall a. a -> Trampolinef686f5f.Trampoline a
gen_5_2_0 = Freef686f5f.suspendF <<< Trampolinef686f5f.done

binds_0_6_1 :: Array Number -> Trampoline0df59c5.Trampoline Number
binds_0_6_1 as = foldl (\b a -> b >>= const (gen_0_6_1 a)) (gen_0_6_1 0.0) as

gen_0_6_1 :: forall a. a -> Trampoline0df59c5.Trampoline a
gen_0_6_1 = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done

rightBindLargeBenchmark :: Benchmark
rightBindLargeBenchmark =
Expand All @@ -121,22 +144,29 @@ rightBindLargeBenchmark =
, inputsPerSize: inputsPerSize
, gen: \n -> vectorOf n (pure 0.0)
, functions:
[ benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds)
, benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< bindsT)
[ benchFn "Free (master)" (Trampoline.runTrampoline <<< binds)
, benchFn "Free v5.2.0" (Trampolinef686f5f.runTrampoline <<< binds_5_2_0)
, benchFn "Free v0.6.1" (Trampoline0df59c5.runTrampoline <<< binds_0_6_1)
]
}
where
inputsPerSize :: Int
inputsPerSize = 1

binds :: Array Number -> Trampolinef686f5f.Trampoline Number
binds :: Array Number -> Trampoline.Trampoline Number
binds as = foldl (\b a -> gen a >>= const b) (gen 0.0) as

gen :: forall a. a -> Trampolinef686f5f.Trampoline a
gen = Freef686f5f.suspendF <<< Trampolinef686f5f.done
gen :: forall a. a -> Trampoline.Trampoline a
gen = Free.suspendF <<< Trampoline.done

binds_5_2_0 :: Array Number -> Trampolinef686f5f.Trampoline Number
binds_5_2_0 as = foldl (\b a -> gen_5_2_0 a >>= const b) (gen_5_2_0 0.0) as

gen_5_2_0 :: forall a. a -> Trampolinef686f5f.Trampoline a
gen_5_2_0 = Freef686f5f.suspendF <<< Trampolinef686f5f.done

bindsT :: Array Number -> Trampoline0df59c5.Trampoline Number
bindsT as = foldl (\b a -> genT a >>= const b) (genT 0.0) as
binds_0_6_1 :: Array Number -> Trampoline0df59c5.Trampoline Number
binds_0_6_1 as = foldl (\b a -> gen_0_6_1 a >>= const b) (gen_0_6_1 0.0) as

genT :: forall a. a -> Trampoline0df59c5.Trampoline a
genT = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done
gen_0_6_1 :: forall a. a -> Trampoline0df59c5.Trampoline a
gen_0_6_1 = Trampoline0df59c5.suspend <<< Trampoline0df59c5.done
3 changes: 3 additions & 0 deletions benchmark/Benchmark/Trampoline.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Benchmark.Trampoline (module Control.Monad.Trampoline) where

import Control.Monad.Trampoline
4 changes: 3 additions & 1 deletion src/Control/Comonad/Cofree.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Control.Comonad.Cofree
( Cofree
, deferCofree
, mkCofree, (:<)
, mkCofree
, (:<)
, head
, tail
, hoistCofree
Expand All @@ -14,6 +15,7 @@ module Control.Comonad.Cofree
) where

import Prelude

import Control.Alternative (class Alternative, (<|>), empty)
import Control.Comonad (class Comonad, extract)
import Control.Extend (class Extend)
Expand Down
Loading