Skip to content

Instantly share code, notes, and snippets.

@thoradam
Created September 28, 2017 00:15
Show Gist options
  • Save thoradam/9e38115f2870dc27e193b146ff106b34 to your computer and use it in GitHub Desktop.
Save thoradam/9e38115f2870dc27e193b146ff106b34 to your computer and use it in GitHub Desktop.
Prepack on PureScript
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
> 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