-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve memory usage with existential state (#21)
* Improve memory usage with existential state * Fix test * Remove ElemSpec * Tweak test diff, names
- Loading branch information
1 parent
ab96274
commit 6470c51
Showing
8 changed files
with
357 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,45 @@ | ||
module Halogen.VDom.Machine | ||
( Machine | ||
, Step(..) | ||
, Step'(..) | ||
, Step | ||
, mkStep | ||
, unStep | ||
, extract | ||
, step | ||
, halt | ||
) where | ||
|
||
import Prelude | ||
|
||
import Effect (Effect) | ||
import Effect.Uncurried (EffectFn1) | ||
import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, mkEffectFn2, runEffectFn1, runEffectFn2) | ||
import Unsafe.Coerce (unsafeCoerce) | ||
|
||
type Machine a b = EffectFn1 a (Step a b) | ||
|
||
data Step a b = Step b (Machine a b) (Effect Unit) | ||
data Step' a b s = Step b s (EffectFn2 s a (Step a b)) (EffectFn1 s Unit) | ||
|
||
foreign import data Step ∷ Type → Type → Type | ||
|
||
mkStep ∷ ∀ a b s. Step' a b s → Step a b | ||
mkStep = unsafeCoerce | ||
|
||
unStep :: ∀ a b r. (∀ s. Step' a b s → r) → Step a b → r | ||
unStep = unsafeCoerce | ||
|
||
-- | Returns the output value of a `Step`. | ||
extract ∷ ∀ a b. Step a b → b | ||
extract (Step x _ _) = x | ||
extract = unStep \(Step x _ _ _) → x | ||
|
||
-- | Runs the next step. | ||
step ∷ ∀ a b. Step a b → EffectFn1 a (Step a b) | ||
step (Step _ m _) = m | ||
step ∷ ∀ a b. EffectFn2 (Step a b) a (Step a b) | ||
step = coerce $ mkEffectFn2 \(Step _ s k _) a → runEffectFn2 k s a | ||
where | ||
coerce ∷ ∀ s. EffectFn2 (Step' a b s) a (Step a b) → EffectFn2 (Step a b) a (Step a b) | ||
coerce = unsafeCoerce | ||
|
||
-- | Runs the finalizer associated with a `Step` | ||
halt ∷ ∀ a b. Step a b → Effect Unit | ||
halt (Step _ _ h) = h | ||
halt ∷ ∀ a b. EffectFn1 (Step a b) Unit | ||
halt = coerce $ mkEffectFn1 \(Step _ s _ k) → runEffectFn1 k s | ||
where | ||
coerce ∷ ∀ s. EffectFn1 (Step' a b s) Unit → EffectFn1 (Step a b) Unit | ||
coerce = unsafeCoerce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters