SlideShare a Scribd company logo
1 of 48
Haste
Same Language, Multiple latforms
Tagless Final Style
Same Syntax, Multiple nterpretations
Nathan Sorenson
@takeoutweight
i
p
haste-lang.org
A Haskell-to-Javascript Compiler
created by Anton Ekblad
+ Full Haskell 2010 Support
(Proper Numbers, Lazy, Pure, Type Classes, …)
+ Nearly all GHC extensions
+ Supports large amount of Hackage
+ Cabal-style build
+ Compact output (~2k hello world)
+ Fast
+ Javascript FFI
+ Browser API
- No Template Haskell
- No GHCi
- No forkIO
- No Weak Pointers
Elm
Haskell-inspired. Strict. Structural typing and FRP.
Purescript
Haskell-inspired. Strict. Structural typing and Effect typing.
Fay
Haskell subset. Lazy. Small & Fast code. No type classes.
GHCJS
Full GHC. Big runtime with GC, Thread scheduler, etc
Browser-Friendly GHC-Compatible
Elm
PureScript
Fay GHCJSHaste
ghc-7.4.2.9: The GHC API
parseModule :: GhcMonad m => ModSummary → m ParsedModule
typeCheckModule :: GhcMonad m => ParsedModule → m TypecheckedModu
desugarModule :: GhcMonad m => TypecheckedModule → m DesugaredModule
coreToStg :: DynFlags → CoreProgram → IO [ StgBinding ]
+---------+
LLVM backend /--->| LLVM IR |--
| +---------+ | LLVM
| v
+------------+ Desugar +------+ STGify +-----+ CodeGen +-----+ | NCG +----------+
| Parse tree |--------->| Core |-------->| STG |--------->| C-- |----+-------->| Assembly |
+------------+ +------+ +-----+ +-----+ | +----------+
| ^
| +---+ | GCC
C backend ---->| C |--/
+---+
https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/GeneratedCode
ghc-7.4.2.9: The GHC API
module StgSyn where
data GenStgExpr bndr occ Source
= StgApp occ [GenStgArg occ]
| StgLit Literal
| StgConApp DataCon [GenStgArg occ]
| StgOpApp StgOp [GenStgArg occ] Type
| StgLam Type [bndr] StgExpr
| StgCase (GenStgExpr bndr occ) (GenStgLiveVars occ) …
| StgLet (GenStgBinding bndr occ) (GenStgExpr bndr occ)
| StgLetNoEscape (GenStgLiveVars occ) (GenStgLiveVars …
| StgSCC CostCentre !Bool !Bool (GenStgExpr bndr occ)
| StgTick Module Int (GenStgExpr bndr occ)
module Data.JSTarget.AST where
-- | Expressions. Completely predictable.
data Exp where
Var :: Var → Exp
Lit :: Lit → Exp
Not :: Exp → Exp
BinOp :: BinOp → Exp → Exp → Exp
Fun :: Maybe Name → [Var] → Stm → Exp
Call :: Arity → Call → Exp → [Exp] → Exp
Index :: Exp → Exp → Exp
Arr :: [Exp] → Exp
AssignEx :: Exp → Exp → Exp
IfEx :: Exp → Exp → Exp → Exp
deriving (Eq, Show)
https://ghc.haskell.org/trac/ghc/ticket/3693
Installing
$ cabal install haste-compiler
$ haste-boot
# Or from source
$ git clone https://github.com/valderman/haste-compiler.git
$ cd haste-compiler
$ cabal sandbox init
$ cabal install
$ haste-boot --local
Building a Haste Project
$ hastec Main.hs # → Main.js
$ hastec --start=asap Main.hs # node Main.js
# Or with via cabal-install
$ haste-inst configure
$ haste-inst build
# installing dependencies (if lucky)
$ haste-inst install contravariant mtl semigroups
Remove Haste Unfriendly Things
use Cabal build-type: Simple, not Custom
remove use of Template Haskell
remove use of ‘vector’ package
# installing dependencies (if unlucky)
$ cabal unpack time
# … remove Haste Unfriendly Things …
$ haste-inst configure
$ haste-inst build --install-jsmods --ghc-options=-UHLINT
$ haste-install-his time-1.4.2 dist/build
$ haste-copy-pkg time-1.4.2 --package-
db=dist/package.conf.inplace
./libraries/haste-lib
module Haste.DOM
addChild :: MonadIO m => Elem → Elem → m ()
elemById :: MonadIO m => ElemID → m (Maybe Elem)
module Haste.JSON
encodeJSON :: JSON → JSString
decodeJSON :: JSString → Either String JSON
module Haste.Graphics.Canvas
setFillColor :: Color → Picture ()
line :: Point → Point → Shape ()
module Haste.Concurrent.Monad
forkIO :: CIO () → CIO ()
putMVar :: MVar a → a → CIO ()
FFI
// javascript.js
function jsGetAttr(elem, prop) {
return elem.getAttribute(prop).toString();
}
-- haskell.hs (compile-time ffi)
foreign import ccall jsGetAttr :: Elem → JSString → IO JSString
-- (in-line javascript, run-time ffi)
f :: String → String → IO Int
f a b = ffi “(function (a,b) {window.tst = a; return 3;})” a b
-- expose to JS, via Haste[“myInc”] or Haste.myInc
export :: FFI a => JSString → a → IO ()
export “myInc” ((x -> return (x + 1)) :: Int → IO Int)
// javascript.js
Haste.myInc(3) // 4
facebook.github.io/react
<div id=“mydiv”>
<button>clickme</button>
</div>
React.DOM.div({idName:“mydiv”},
[React.DOM.button({},
[“clickme”])])
React.DOM.div({idName:“mydiv”},
[React.DOM.button({},
[“clickme”])])
<div id=“mydiv”>
<button>click{{me}}</button>
</div>
function(me) {
return React.DOM.div({idName:“mydiv”},
[React.DOM.button({},
[“click”+me])]);
}
<div id=“mydiv”>
<button>click{{me}}</button>
</div>
div :: [Attr] → [JSPtr] → JSPtr
button :: [Attr] → [JSPtr] → JSPtr
text :: String → JSPtr
EDSL
div :: [Attr] → [JSPtr] → JSPtr
button :: [Attr] → [JSPtr] → JSPtr
text :: String → JSPtr
EDSS
Embedded Domain Specific Syntax
Tagless Final Style
Tagless Final Style
Discovered by Oleg Kiselyov
Tagless Final Style
Discovered by Oleg Kiselyov
But don’t be scared.
Initial Style
data Html = Div [Attr] [Html]
| Button [Attr] [Html]
| Text String
client :: Html → JSPtr
client (Div attrs children) = …
client (Button attrs children) = …
client (Text str) = …
server :: Html → String
server (Div attrs children) = …
server (Button attrs children) = …
server (Text str) = …
i
i
server :: Html → String
server (Div attrs children) =
“<div” ++ show attrs ++ “>”
++ concatMap server children
++ “</div>”
server (Button attrs children) =
“<button” ++ show attrs ++ “>”
++ concatMap server children
++ “</button>”
server (Text str) = str
Initial Style
data Html =
Div [Attr] [Html]
| Button [Attr] [Html]
| Text String
class Html i where
div :: [Attr] → [ i ] → i
button :: [Attr] → [ i ] → i
text :: String → i
Final Style
Final Style
class Html i where
div :: [Attr] → [i] → i
button :: [Attr] → [i] → i
text :: String → i
-- Initial Style
data Html =
Div [Attr] [Html]
| Button [Attr] [Html]
| Text String
Final Style
class Html i where
div :: [Attr] → [i] → i
button :: [Attr] → [i] → i
text :: String → i
-- Initial Style (GADT)
data Html where
Div :: [Attr] → [Html] → Html
Button :: [Attr] → [Html] → Html
Text :: String → Html
Final Style
class Html i where
div :: [Attr] → [i] → i
button :: [Attr] → [i] → i
text :: String → i
instance Html String where
div attrs children = …
button attrs children = …
text str = …
instance Html JSPtr where
div attrs children = …
button attrs children = …
text str = …
i
i
srv :: Html→String
srv (Div attrs children) =
“<div” ++ show attrs ++ “>”
++ concatMap srv children
++ “</div>”
srv (Button attrs children) =
“<button” ++ show attrs ++ “>”
++ concatMap srv children
++ “</button>”
srv (Text str) = str
instance Html String where
div attrs children =
“<div” ++ show attrs ++ “>”
++ concatMap srv children
++ “</div>”
button attrs children =
“<button” ++ show attrs ++ “>”
++ concatMap srv children
++ “</button>”
text str = str
instance Html String where
-- div :: [Attr] → [i] → i
div attrs children =
“<div” ++ show attrs ++ “>”
++ concatMap ??? children
++ “</div>”
-- button :: [Attr] → [i] → i
button attrs children =
“<button” ++ show attrs ++ “>”
++ concatMap ??? children
++ “</button>”
-- text:: String → i
text str = str
instance Html String where
-- div :: [Attr] → [i] → i
div attrs children =
“<div” ++ show attrs ++ “>”
++ concatMap id children
++ “</div>”
-- button :: [Attr] → [i] → i
button attrs children =
“<button” ++ show attrs ++ “>”
++ concatMap id children
++ “</button>”
-- text:: String → i
text str = str
instance Html String where
-- div :: [Attr] → [i] → i
div attrs children =
“<div” ++ show attrs ++ “>”
++ concat children
++ “</div>”
-- button :: [Attr] → [i] → i
button attrs children =
“<button” ++ show attrs ++ “>”
++ concat children
++ “</button>”
-- text:: String → i
text str = str
-- Initial Style
i :: Html
i = Div [] [(Button [] [Text “clickMe”])]
iOut :: String
iOut = server i
-- Final Style
f :: (Html i) => i
f = div [] [(button [] [text “clickMe”])]
fOut = f :: String
class Math (i :: * ) where
lit :: Int → i
(+) :: i → i → i
(>) :: i → i → i
instance Math Int where …
instance Math String where …
i
i
class Math (i :: *→*) where
lit :: Int → i Int
(+) :: i Int → i Int → i Int
(>) :: i Int → i Int → i Bool
class Math (i :: *→*) where
lit :: Int → i Int
(+) :: i Int → i Int → i Int
(>) :: i Int → i Int → i Bool
newtype Eval a = Eval {eval :: a}
instance Math Eval where …
newtype Pretty a = Pretty {pp :: String}
instance Math Pretty where …
a = (lit 1) > ((lit 2) + (lit 3))
e = eval a -- False
p = pp a -- “(1 > (2 + 3))”
i
i
class Html i where
div :: [Attr] → [i] → i
button :: [Attr] → [i] → i
text :: String → i
instance SafariHtml String where
webkitElt attrs children) = …
instance SafariHtml JSPtr where
webkitElt attrs children) = …
class SafariHtml i where
webkitElt :: [Attr] → [i] → i
Language Extensibility
i
i
f :: (Html i, SafariHtml i) => i
f = div [] [(webkitElt [] [text “clickMe”])]
fOut = f :: String
Language Extensibility
div :: (Attr a, Html i) => [a] → [i] → i
-- div [idName “mydiv”] []
button :: (Attr a, Html i) => [a] → [i] → i
-- button [idName “mybtn”, disabled True] []
class Attr a where
idName :: String → a
disabled :: Bool → a
instance Attr DivAttr where
idName s = …
disabled b = … instance Attr ButtonAttr where
idName s = …
disabled b = …
newtype ButtonAttr
newtype DivAttr
i
i
div :: (Html i) => [DivAttr] → [i] → i
-- div [idName “mydiv”] []
button :: (Html i) => [ButtonAttr] → [i] → i
-- button [idName “mybtn”, disabled True] []
class IdA a where
idName :: String → a
class DisabledA a where
disabled :: Bool → a
instance IdA ButtonAttr where
idName s = …
instance DisabledA ButtonAttr where
disabled b = …
newtype ButtonAttrinstance IdA DivAttr where
idName s = …
newtype DivAttr
i
i
i
type src form
<img>
instance
SrcA ImgAttr
<input>
instance
TypeA InputAttr
instance
SrcA InputAttr
instance
FormA InputAttr
<button
>
instance
TypeA ButtonAttr
instance
FormA ButtonAttr
<label>
instance
FormA LabelAttr
i
i
i
i i
i
i
Typed Tagless Final Course Notes
okmij.org/ftp/tagless-final/course/lecture.pdf
haste-lang.org
“Haskell in the Browser With Haste” Lars Kuhtz
alephcloud.github.io/bayhac2014/slides
facebook.github.io/react
github.com/takeoutweight @takeoutweight

More Related Content

What's hot

[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가
[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가
[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가Hwanhee Kim
 
Hyosung 1800 ce-atm-machine-owners-manual
Hyosung 1800 ce-atm-machine-owners-manualHyosung 1800 ce-atm-machine-owners-manual
Hyosung 1800 ce-atm-machine-owners-manualpdfshearing
 
ONOS - multiple instance setting(Distributed SDN Controller)
ONOS - multiple instance setting(Distributed SDN Controller)ONOS - multiple instance setting(Distributed SDN Controller)
ONOS - multiple instance setting(Distributed SDN Controller)sangyun han
 
Aula 01- web designer
Aula 01- web designerAula 01- web designer
Aula 01- web designerRoney Sousa
 
Arquitetura ibm pc
Arquitetura ibm pcArquitetura ibm pc
Arquitetura ibm pcTiago
 
오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdf
오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdf오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdf
오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdfTae wook kang
 
기술 명세서
기술 명세서기술 명세서
기술 명세서Daniel Shin
 
Áreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de SoftwareÁreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de SoftwareElaine Cecília Gatto
 
Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...Unity Technologies
 
Narrative skill of game content development
Narrative skill of game content developmentNarrative skill of game content development
Narrative skill of game content developmentDurgesh Pandey
 
Double Delta Encoding. Lightning Talk for Infracoders 3
Double Delta Encoding. Lightning Talk for Infracoders 3Double Delta Encoding. Lightning Talk for Infracoders 3
Double Delta Encoding. Lightning Talk for Infracoders 3Oliver Moser
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d GameIsfand yar Khan
 
Level design for games
Level design for gamesLevel design for games
Level design for gamesJayyes
 
Game Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationGame Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationNick Pruehs
 
Introduction to LEGO SERIOUS PLAY with Natalie Sutton
Introduction to LEGO SERIOUS PLAY with Natalie SuttonIntroduction to LEGO SERIOUS PLAY with Natalie Sutton
Introduction to LEGO SERIOUS PLAY with Natalie SuttonNatalie Sutton
 
Jenkins with Unity3d & Android
Jenkins with Unity3d & Android Jenkins with Unity3d & Android
Jenkins with Unity3d & Android 종국 임
 

What's hot (20)

[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가
[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가
[NDC2016] 신경망은컨텐츠자동생성의꿈을꾸는가
 
Hyosung 1800 ce-atm-machine-owners-manual
Hyosung 1800 ce-atm-machine-owners-manualHyosung 1800 ce-atm-machine-owners-manual
Hyosung 1800 ce-atm-machine-owners-manual
 
CSS Grid Layout na prática
CSS Grid Layout na práticaCSS Grid Layout na prática
CSS Grid Layout na prática
 
ONOS - multiple instance setting(Distributed SDN Controller)
ONOS - multiple instance setting(Distributed SDN Controller)ONOS - multiple instance setting(Distributed SDN Controller)
ONOS - multiple instance setting(Distributed SDN Controller)
 
Aula 01- web designer
Aula 01- web designerAula 01- web designer
Aula 01- web designer
 
Gaming Testing
Gaming TestingGaming Testing
Gaming Testing
 
Avaliação de Interface
Avaliação de InterfaceAvaliação de Interface
Avaliação de Interface
 
Arquitetura ibm pc
Arquitetura ibm pcArquitetura ibm pc
Arquitetura ibm pc
 
오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdf
오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdf오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdf
오픈소스로 쉽게 따라해보는 Unreal과 IoT 연계 및 개발 방법 소개.pdf
 
기술 명세서
기술 명세서기술 명세서
기술 명세서
 
Áreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de SoftwareÁreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de Software
 
Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...
 
Narrative skill of game content development
Narrative skill of game content developmentNarrative skill of game content development
Narrative skill of game content development
 
Double Delta Encoding. Lightning Talk for Infracoders 3
Double Delta Encoding. Lightning Talk for Infracoders 3Double Delta Encoding. Lightning Talk for Infracoders 3
Double Delta Encoding. Lightning Talk for Infracoders 3
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
 
Rendering Battlefield 4 with Mantle
Rendering Battlefield 4 with MantleRendering Battlefield 4 with Mantle
Rendering Battlefield 4 with Mantle
 
Level design for games
Level design for gamesLevel design for games
Level design for games
 
Game Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationGame Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content Generation
 
Introduction to LEGO SERIOUS PLAY with Natalie Sutton
Introduction to LEGO SERIOUS PLAY with Natalie SuttonIntroduction to LEGO SERIOUS PLAY with Natalie Sutton
Introduction to LEGO SERIOUS PLAY with Natalie Sutton
 
Jenkins with Unity3d & Android
Jenkins with Unity3d & Android Jenkins with Unity3d & Android
Jenkins with Unity3d & Android
 

Viewers also liked

setParamを用いた原音設定の解説
setParamを用いた原音設定の解説setParamを用いた原音設定の解説
setParamを用いた原音設定の解説Tatsumi
 
Influencia británica en la decadencia argentina
Influencia británica en la decadencia argentinaInfluencia británica en la decadencia argentina
Influencia británica en la decadencia argentinaRamón Copa
 
ダウンサイジング時代のプロセス改善モデル(OHP)
ダウンサイジング時代のプロセス改善モデル(OHP)ダウンサイジング時代のプロセス改善モデル(OHP)
ダウンサイジング時代のプロセス改善モデル(OHP)Makoto SAKAI
 
Key isi guerrilla handler on akhtar abdul rehman
Key isi guerrilla handler on akhtar abdul rehmanKey isi guerrilla handler on akhtar abdul rehman
Key isi guerrilla handler on akhtar abdul rehmanAgha A
 
Taller expedición de datos OPEN DATA - DANE - Sharecollab - Work&Go
Taller expedición de datos  OPEN DATA - DANE -  Sharecollab - Work&GoTaller expedición de datos  OPEN DATA - DANE -  Sharecollab - Work&Go
Taller expedición de datos OPEN DATA - DANE - Sharecollab - Work&GoSharecollab
 
TripDesign.Us presents Eat Play Chill ; #Meghalaya
TripDesign.Us presents Eat Play Chill ; #MeghalayaTripDesign.Us presents Eat Play Chill ; #Meghalaya
TripDesign.Us presents Eat Play Chill ; #MeghalayaRakesh Debur
 
Dove Science Academy Audit - a Gulen operated charter school
Dove Science Academy Audit - a Gulen operated charter schoolDove Science Academy Audit - a Gulen operated charter school
Dove Science Academy Audit - a Gulen operated charter schoolGulen Cemaat
 
Boletín 17/03/2017
Boletín 17/03/2017Boletín 17/03/2017
Boletín 17/03/2017Openbank
 

Viewers also liked (10)

EL PECADO
EL PECADOEL PECADO
EL PECADO
 
setParamを用いた原音設定の解説
setParamを用いた原音設定の解説setParamを用いた原音設定の解説
setParamを用いた原音設定の解説
 
Influencia británica en la decadencia argentina
Influencia británica en la decadencia argentinaInfluencia británica en la decadencia argentina
Influencia británica en la decadencia argentina
 
ダウンサイジング時代のプロセス改善モデル(OHP)
ダウンサイジング時代のプロセス改善モデル(OHP)ダウンサイジング時代のプロセス改善モデル(OHP)
ダウンサイジング時代のプロセス改善モデル(OHP)
 
Key isi guerrilla handler on akhtar abdul rehman
Key isi guerrilla handler on akhtar abdul rehmanKey isi guerrilla handler on akhtar abdul rehman
Key isi guerrilla handler on akhtar abdul rehman
 
Taller expedición de datos OPEN DATA - DANE - Sharecollab - Work&Go
Taller expedición de datos  OPEN DATA - DANE -  Sharecollab - Work&GoTaller expedición de datos  OPEN DATA - DANE -  Sharecollab - Work&Go
Taller expedición de datos OPEN DATA - DANE - Sharecollab - Work&Go
 
Ajax 応用
Ajax 応用Ajax 応用
Ajax 応用
 
TripDesign.Us presents Eat Play Chill ; #Meghalaya
TripDesign.Us presents Eat Play Chill ; #MeghalayaTripDesign.Us presents Eat Play Chill ; #Meghalaya
TripDesign.Us presents Eat Play Chill ; #Meghalaya
 
Dove Science Academy Audit - a Gulen operated charter school
Dove Science Academy Audit - a Gulen operated charter schoolDove Science Academy Audit - a Gulen operated charter school
Dove Science Academy Audit - a Gulen operated charter school
 
Boletín 17/03/2017
Boletín 17/03/2017Boletín 17/03/2017
Boletín 17/03/2017
 

Similar to Haste (Same Language, Multiple Platforms) and Tagless Final Style (Same Syntax, Multiple Interpretations)

Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitVaclav Pech
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developersPuneet Behl
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185Mahmoud Samir Fayed
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup itPROIDEA
 
Python Peculiarities
Python PeculiaritiesPython Peculiarities
Python Peculiaritiesnoamt
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosEdgar Suarez
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeLaurence Svekis ✔
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceMaarten Balliauw
 
Acceptance Testing with Webrat
Acceptance Testing with WebratAcceptance Testing with Webrat
Acceptance Testing with WebratLuismi Cavallé
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 

Similar to Haste (Same Language, Multiple Platforms) and Tagless Final Style (Same Syntax, Multiple Interpretations) (20)

Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
PureScript & Pux
PureScript & PuxPureScript & Pux
PureScript & Pux
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developers
 
JQuery Flot
JQuery FlotJQuery Flot
JQuery Flot
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
 
Python Peculiarities
Python PeculiaritiesPython Peculiarities
Python Peculiarities
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
Acceptance Testing with Webrat
Acceptance Testing with WebratAcceptance Testing with Webrat
Acceptance Testing with Webrat
 
Beware sharp tools
Beware sharp toolsBeware sharp tools
Beware sharp tools
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
Groovy kind of test
Groovy kind of testGroovy kind of test
Groovy kind of test
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 

Haste (Same Language, Multiple Platforms) and Tagless Final Style (Same Syntax, Multiple Interpretations)

  • 1. Haste Same Language, Multiple latforms Tagless Final Style Same Syntax, Multiple nterpretations Nathan Sorenson @takeoutweight i p
  • 3. + Full Haskell 2010 Support (Proper Numbers, Lazy, Pure, Type Classes, …) + Nearly all GHC extensions + Supports large amount of Hackage + Cabal-style build + Compact output (~2k hello world) + Fast + Javascript FFI + Browser API
  • 4. - No Template Haskell - No GHCi - No forkIO - No Weak Pointers
  • 5. Elm Haskell-inspired. Strict. Structural typing and FRP. Purescript Haskell-inspired. Strict. Structural typing and Effect typing. Fay Haskell subset. Lazy. Small & Fast code. No type classes. GHCJS Full GHC. Big runtime with GC, Thread scheduler, etc
  • 7. ghc-7.4.2.9: The GHC API parseModule :: GhcMonad m => ModSummary → m ParsedModule typeCheckModule :: GhcMonad m => ParsedModule → m TypecheckedModu desugarModule :: GhcMonad m => TypecheckedModule → m DesugaredModule coreToStg :: DynFlags → CoreProgram → IO [ StgBinding ]
  • 8. +---------+ LLVM backend /--->| LLVM IR |-- | +---------+ | LLVM | v +------------+ Desugar +------+ STGify +-----+ CodeGen +-----+ | NCG +----------+ | Parse tree |--------->| Core |-------->| STG |--------->| C-- |----+-------->| Assembly | +------------+ +------+ +-----+ +-----+ | +----------+ | ^ | +---+ | GCC C backend ---->| C |--/ +---+ https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/GeneratedCode ghc-7.4.2.9: The GHC API
  • 9. module StgSyn where data GenStgExpr bndr occ Source = StgApp occ [GenStgArg occ] | StgLit Literal | StgConApp DataCon [GenStgArg occ] | StgOpApp StgOp [GenStgArg occ] Type | StgLam Type [bndr] StgExpr | StgCase (GenStgExpr bndr occ) (GenStgLiveVars occ) … | StgLet (GenStgBinding bndr occ) (GenStgExpr bndr occ) | StgLetNoEscape (GenStgLiveVars occ) (GenStgLiveVars … | StgSCC CostCentre !Bool !Bool (GenStgExpr bndr occ) | StgTick Module Int (GenStgExpr bndr occ)
  • 10. module Data.JSTarget.AST where -- | Expressions. Completely predictable. data Exp where Var :: Var → Exp Lit :: Lit → Exp Not :: Exp → Exp BinOp :: BinOp → Exp → Exp → Exp Fun :: Maybe Name → [Var] → Stm → Exp Call :: Arity → Call → Exp → [Exp] → Exp Index :: Exp → Exp → Exp Arr :: [Exp] → Exp AssignEx :: Exp → Exp → Exp IfEx :: Exp → Exp → Exp → Exp deriving (Eq, Show)
  • 12.
  • 13. Installing $ cabal install haste-compiler $ haste-boot # Or from source $ git clone https://github.com/valderman/haste-compiler.git $ cd haste-compiler $ cabal sandbox init $ cabal install $ haste-boot --local
  • 14. Building a Haste Project $ hastec Main.hs # → Main.js $ hastec --start=asap Main.hs # node Main.js # Or with via cabal-install $ haste-inst configure $ haste-inst build # installing dependencies (if lucky) $ haste-inst install contravariant mtl semigroups
  • 15. Remove Haste Unfriendly Things use Cabal build-type: Simple, not Custom remove use of Template Haskell remove use of ‘vector’ package # installing dependencies (if unlucky) $ cabal unpack time # … remove Haste Unfriendly Things … $ haste-inst configure $ haste-inst build --install-jsmods --ghc-options=-UHLINT $ haste-install-his time-1.4.2 dist/build $ haste-copy-pkg time-1.4.2 --package- db=dist/package.conf.inplace
  • 16. ./libraries/haste-lib module Haste.DOM addChild :: MonadIO m => Elem → Elem → m () elemById :: MonadIO m => ElemID → m (Maybe Elem) module Haste.JSON encodeJSON :: JSON → JSString decodeJSON :: JSString → Either String JSON module Haste.Graphics.Canvas setFillColor :: Color → Picture () line :: Point → Point → Shape () module Haste.Concurrent.Monad forkIO :: CIO () → CIO () putMVar :: MVar a → a → CIO ()
  • 17. FFI // javascript.js function jsGetAttr(elem, prop) { return elem.getAttribute(prop).toString(); } -- haskell.hs (compile-time ffi) foreign import ccall jsGetAttr :: Elem → JSString → IO JSString -- (in-line javascript, run-time ffi) f :: String → String → IO Int f a b = ffi “(function (a,b) {window.tst = a; return 3;})” a b -- expose to JS, via Haste[“myInc”] or Haste.myInc export :: FFI a => JSString → a → IO () export “myInc” ((x -> return (x + 1)) :: Int → IO Int) // javascript.js Haste.myInc(3) // 4
  • 22. div :: [Attr] → [JSPtr] → JSPtr button :: [Attr] → [JSPtr] → JSPtr text :: String → JSPtr EDSL
  • 23. div :: [Attr] → [JSPtr] → JSPtr button :: [Attr] → [JSPtr] → JSPtr text :: String → JSPtr EDSS Embedded Domain Specific Syntax
  • 25. Tagless Final Style Discovered by Oleg Kiselyov
  • 26. Tagless Final Style Discovered by Oleg Kiselyov But don’t be scared.
  • 27. Initial Style data Html = Div [Attr] [Html] | Button [Attr] [Html] | Text String client :: Html → JSPtr client (Div attrs children) = … client (Button attrs children) = … client (Text str) = … server :: Html → String server (Div attrs children) = … server (Button attrs children) = … server (Text str) = … i i
  • 28. server :: Html → String server (Div attrs children) = “<div” ++ show attrs ++ “>” ++ concatMap server children ++ “</div>” server (Button attrs children) = “<button” ++ show attrs ++ “>” ++ concatMap server children ++ “</button>” server (Text str) = str
  • 29. Initial Style data Html = Div [Attr] [Html] | Button [Attr] [Html] | Text String
  • 30. class Html i where div :: [Attr] → [ i ] → i button :: [Attr] → [ i ] → i text :: String → i Final Style
  • 31. Final Style class Html i where div :: [Attr] → [i] → i button :: [Attr] → [i] → i text :: String → i -- Initial Style data Html = Div [Attr] [Html] | Button [Attr] [Html] | Text String
  • 32. Final Style class Html i where div :: [Attr] → [i] → i button :: [Attr] → [i] → i text :: String → i -- Initial Style (GADT) data Html where Div :: [Attr] → [Html] → Html Button :: [Attr] → [Html] → Html Text :: String → Html
  • 33. Final Style class Html i where div :: [Attr] → [i] → i button :: [Attr] → [i] → i text :: String → i instance Html String where div attrs children = … button attrs children = … text str = … instance Html JSPtr where div attrs children = … button attrs children = … text str = … i i
  • 34. srv :: Html→String srv (Div attrs children) = “<div” ++ show attrs ++ “>” ++ concatMap srv children ++ “</div>” srv (Button attrs children) = “<button” ++ show attrs ++ “>” ++ concatMap srv children ++ “</button>” srv (Text str) = str
  • 35. instance Html String where div attrs children = “<div” ++ show attrs ++ “>” ++ concatMap srv children ++ “</div>” button attrs children = “<button” ++ show attrs ++ “>” ++ concatMap srv children ++ “</button>” text str = str
  • 36. instance Html String where -- div :: [Attr] → [i] → i div attrs children = “<div” ++ show attrs ++ “>” ++ concatMap ??? children ++ “</div>” -- button :: [Attr] → [i] → i button attrs children = “<button” ++ show attrs ++ “>” ++ concatMap ??? children ++ “</button>” -- text:: String → i text str = str
  • 37. instance Html String where -- div :: [Attr] → [i] → i div attrs children = “<div” ++ show attrs ++ “>” ++ concatMap id children ++ “</div>” -- button :: [Attr] → [i] → i button attrs children = “<button” ++ show attrs ++ “>” ++ concatMap id children ++ “</button>” -- text:: String → i text str = str
  • 38. instance Html String where -- div :: [Attr] → [i] → i div attrs children = “<div” ++ show attrs ++ “>” ++ concat children ++ “</div>” -- button :: [Attr] → [i] → i button attrs children = “<button” ++ show attrs ++ “>” ++ concat children ++ “</button>” -- text:: String → i text str = str
  • 39. -- Initial Style i :: Html i = Div [] [(Button [] [Text “clickMe”])] iOut :: String iOut = server i -- Final Style f :: (Html i) => i f = div [] [(button [] [text “clickMe”])] fOut = f :: String
  • 40. class Math (i :: * ) where lit :: Int → i (+) :: i → i → i (>) :: i → i → i instance Math Int where … instance Math String where … i i
  • 41. class Math (i :: *→*) where lit :: Int → i Int (+) :: i Int → i Int → i Int (>) :: i Int → i Int → i Bool
  • 42. class Math (i :: *→*) where lit :: Int → i Int (+) :: i Int → i Int → i Int (>) :: i Int → i Int → i Bool newtype Eval a = Eval {eval :: a} instance Math Eval where … newtype Pretty a = Pretty {pp :: String} instance Math Pretty where … a = (lit 1) > ((lit 2) + (lit 3)) e = eval a -- False p = pp a -- “(1 > (2 + 3))” i i
  • 43. class Html i where div :: [Attr] → [i] → i button :: [Attr] → [i] → i text :: String → i instance SafariHtml String where webkitElt attrs children) = … instance SafariHtml JSPtr where webkitElt attrs children) = … class SafariHtml i where webkitElt :: [Attr] → [i] → i Language Extensibility i i
  • 44. f :: (Html i, SafariHtml i) => i f = div [] [(webkitElt [] [text “clickMe”])] fOut = f :: String Language Extensibility
  • 45. div :: (Attr a, Html i) => [a] → [i] → i -- div [idName “mydiv”] [] button :: (Attr a, Html i) => [a] → [i] → i -- button [idName “mybtn”, disabled True] [] class Attr a where idName :: String → a disabled :: Bool → a instance Attr DivAttr where idName s = … disabled b = … instance Attr ButtonAttr where idName s = … disabled b = … newtype ButtonAttr newtype DivAttr i i
  • 46. div :: (Html i) => [DivAttr] → [i] → i -- div [idName “mydiv”] [] button :: (Html i) => [ButtonAttr] → [i] → i -- button [idName “mybtn”, disabled True] [] class IdA a where idName :: String → a class DisabledA a where disabled :: Bool → a instance IdA ButtonAttr where idName s = … instance DisabledA ButtonAttr where disabled b = … newtype ButtonAttrinstance IdA DivAttr where idName s = … newtype DivAttr i i i
  • 47. type src form <img> instance SrcA ImgAttr <input> instance TypeA InputAttr instance SrcA InputAttr instance FormA InputAttr <button > instance TypeA ButtonAttr instance FormA ButtonAttr <label> instance FormA LabelAttr i i i i i i i
  • 48. Typed Tagless Final Course Notes okmij.org/ftp/tagless-final/course/lecture.pdf haste-lang.org “Haskell in the Browser With Haste” Lars Kuhtz alephcloud.github.io/bayhac2014/slides facebook.github.io/react github.com/takeoutweight @takeoutweight