Created
September 28, 2017 00:15
-
-
Save thoradam/9e38115f2870dc27e193b146ff106b34 to your computer and use it in GitHub Desktop.
Prepack on PureScript
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
module Main where | |
import Prelude | |
import Control.Monad.Eff.Console (log) | |
import Run (FProxy, Run, SProxy(SProxy), interpret, liftEffect, runBase) | |
data Speak a = Talk String a | Shout String a | |
derive instance functorSpeak :: Functor Speak | |
type SPEAK = FProxy Speak | |
speak = (SProxy :: SProxy "speak") | |
talk :: forall r. String -> Run (speak :: SPEAK | r) Unit | |
talk s = liftEffect speak $ Talk (if s == "" then "..." else s) unit | |
shout :: forall r. String -> Run (speak :: SPEAK | r) Unit | |
shout s = liftEffect speak $ Shout (if s == "" then "!!!" else s <> "!") unit | |
talkProg :: Run (speak :: SPEAK) Unit | |
talkProg = do | |
talk "" | |
talk "Hi" | |
shout "Hi" | |
main = do | |
talkProg | |
# interpret speak case _ of | |
Talk str a -> log str *> pure a | |
Shout str a -> log str *> pure a | |
# runBase |
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
> pulp browserify --to out.js | |
> prepack out.js | |
console.log("..."); | |
console.log("Hi"); | |
console.log("Hi!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment