Skip to content

Commit d546821

Browse files
authored
Remove sugar only type classes (#94)
* Remove sugar only type classes * Update examples * Update docs * Update benchmarks * Update benchmarks
1 parent 20f77e4 commit d546821

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1084
-1121
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ update model = case _ of
5050
5151
-- | `view` is called whenever the model is updated
5252
view :: Model -> Html Message
53-
view model = HE.main "main" [
54-
HE.button [HA.onClick Decrement] "-",
53+
view model = HE.main [HA.id "main"] [
54+
HE.button [HA.onClick Decrement] [HE.text "-"],
5555
HE.text $ show model,
56-
HE.button [HA.onClick Increment] "+"
56+
HE.button [HA.onClick Increment] [HE.text "+"]
5757
]
5858
5959
-- | Events that come from outside the `view`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require('./dce-output/Main').main();
1+
require('./output-es/Main').main();
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "js-framework-benchmark-keyed-flame",
33
"sideEffects": false,
4-
"version": "1.0.0",
4+
"version": "1.6.0",
55
"description": "Purescript Flame JS Benchmark",
66
"main": "index.js",
77
"js-framework-benchmark": {
8-
"frameworkVersion": "1.0.0"
8+
"frameworkVersion": "1.6.0"
99
},
1010
"scripts": {
1111
"postinstall": "spago install",
1212
"clean": "rm -rf dist output .spago node_modules",
1313
"build": "spago build",
14-
"build-prod": "spago build --purs-args '--codegen corefn,js' && zephyr -f Main.main && webpack --config=webpack.flame.config.js"
14+
"build-prod": "spago build && webpack --config=webpack.flame.config.js"
1515
},
1616
"keywords": [
1717
"purescript",
@@ -25,9 +25,10 @@
2525
"url": "https://github.com/krausest/js-framework-benchmark.git"
2626
},
2727
"devDependencies": {
28-
"purescript": "0.14.4",
29-
"spago": "0.20.3",
30-
"webpack": "^4.44.1",
28+
"purescript": "0.15.15",
29+
"purs-backend-es": "^1.4.3",
30+
"spago": "0.21.0",
31+
"webpack": "^4.47.0",
3132
"webpack-cli": "^3.3.12"
3233
}
3334
}

benchmarks/js-framework-benchmark/keyed/packages.dhall

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let upstream =
2-
https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220527/packages.dhall
3-
sha256:15dd8041480502850e4043ea2977ed22d6ab3fc24d565211acde6f8c5152a799
2+
https://github.com/purescript/package-sets/releases/download/psc-0.15.15-20250904/packages.dhall
3+
sha256:65df863430bac51dc71eb6c31d60f837bccf3837ddae929e1bc53830d299ab37
44

55
let overrides = {=}
66

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{ name = "js-framework-benchmark-flame"
2-
, dependencies = [
3-
"flame",
4-
"aff",
5-
"arrays",
6-
"effect",
7-
"maybe",
8-
"prelude" ]
2+
, dependencies =
3+
[ "aff"
4+
, "arrays"
5+
, "effect"
6+
, "flame"
7+
, "maybe"
8+
, "prelude"
9+
, "tuples"
10+
, "web-dom"
11+
]
912
, packages = ./packages.dhall
1013
, sources = [ "src/**/*.purs" ]
14+
, backend = "npx purs-backend-es build"
1115
}

benchmarks/js-framework-benchmark/keyed/src/Main.purs

Lines changed: 134 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -18,161 +18,164 @@ import Flame.Html.Element as HE
1818
import Flame.Types (NodeData)
1919
import Web.DOM.ParentNode (QuerySelector(..))
2020

21-
data Message =
22-
Create Int |
23-
DisplayCreated (Array Row) |
24-
AppendOneThousand |
25-
DisplayAppended (Array Row) |
26-
UpdateEveryTenth |
27-
Clear |
28-
Swap |
29-
Remove Int |
30-
Select Int
31-
32-
type Model = {
33-
rows :: Array Row,
34-
lastID :: Int
35-
}
36-
37-
type Row = {
38-
id :: Int,
39-
label :: String,
40-
selected :: Boolean
41-
}
42-
43-
type Button = {
44-
id :: String,
45-
label :: String,
46-
message :: Message
47-
}
48-
49-
foreign import createRandomNRows_ :: EffectFn2 Int Int (Array Row)
50-
51-
createRandomNRows :: Int -> Int -> Aff (Array Row)
21+
data Message
22+
= Create Int
23+
| DisplayCreated (Array Row)
24+
| AppendOneThousand
25+
| DisplayAppended (Array Row)
26+
| UpdateEveryTenth
27+
| Clear
28+
| Swap
29+
| Remove Int
30+
| Select Int
31+
32+
type Model =
33+
{ rows Array Row
34+
, lastID Int
35+
}
36+
37+
type Row =
38+
{ id Int
39+
, label String
40+
, selected Boolean
41+
}
42+
43+
type Button =
44+
{ id String
45+
, label String
46+
, message Message
47+
}
48+
49+
foreign import createRandomNRows_ EffectFn2 Int Int (Array Row)
50+
51+
createRandomNRows Int Int Aff (Array Row)
5252
createRandomNRows n lastID = liftEffect (EU.runEffectFn2 createRandomNRows_ n lastID)
5353

54-
main :: Effect Unit
55-
main = F.mount_ (QuerySelector "body") {
56-
model: model,
57-
subscribe: [],
58-
view,
59-
update
60-
}
61-
62-
model :: Model
63-
model = {
64-
rows: [],
65-
lastID: 0
66-
}
67-
68-
view :: Model -> Html Message
69-
view model = HE.div [HA.class' "container"] [
70-
jumbotron,
71-
HE.table [HA.class' "table table-hover table-striped test-data"] [
72-
HE.tbody_ (map renderLazyRow model.rows)
73-
],
74-
footer
75-
]
76-
77-
jumbotron :: Html Message
78-
jumbotron = HE.div [ HA.class' "jumbotron" ] [
79-
HE.div [ HA.class' "row" ] [
80-
HE.div [ HA.class' "col-md-6" ] [
81-
HE.h1_ [ HE.text "Flame 1.0.0 (keyed)" ]
82-
],
83-
HE.div [ HA.class' "col-md-6" ] [
84-
map renderActionButton buttons
85-
]
86-
]
87-
]
88-
89-
renderActionButton :: Button -> Html Message
90-
renderActionButton button = HE.div [ HA.class' "col-sm-6 smallpad" ] [
91-
HE.button [
92-
HA.class' "btn btn-primary btn-block",
93-
HA.id button.id,
94-
HA.createAttribute "ref" "text",
95-
HA.onClick button.message
96-
] [ HE.text button.label ]
97-
]
98-
99-
buttons :: Array Button
100-
buttons = [
101-
{ id: "run", label: "Create 1,000 rows", message: Create 1000 },
102-
{ id: "runlots", label: "Create 10,000 rows", message: Create 10000 },
103-
{ id: "add", label: "Append 1,000 rows", message: AppendOneThousand },
104-
{ id: "update", label: "Update every 10th row", message: UpdateEveryTenth },
105-
{ id: "clear", label: "Clear", message: Clear },
106-
{ id: "swaprows", label: "Swap Rows", message: Swap }
107-
]
108-
109-
renderLazyRow :: Row -> Html Message
54+
main Effect Unit
55+
main = F.mount_ (QuerySelector "body")
56+
{ model: model
57+
, subscribe: []
58+
, view
59+
, update
60+
}
61+
62+
model Model
63+
model =
64+
{ rows: []
65+
, lastID: 0
66+
}
67+
68+
view Model Html Message
69+
view model = HE.div [ HA.class' "container" ]
70+
[ jumbotron
71+
, HE.table [ HA.class' "table table-hover table-striped test-data" ]
72+
[ HE.tbody_ (map renderLazyRow model.rows)
73+
]
74+
, footer
75+
]
76+
77+
jumbotron Html Message
78+
jumbotron = HE.div [ HA.class' "jumbotron" ]
79+
[ HE.div [ HA.class' "row" ]
80+
[ HE.div [ HA.class' "col-md-6" ]
81+
[ HE.h1_ [ HE.text "Flame 1.0.0 (keyed)" ]
82+
]
83+
, HE.div [ HA.class' "col-md-6" ] (map renderActionButton buttons)
84+
85+
]
86+
]
87+
88+
renderActionButton Button Html Message
89+
renderActionButton button = HE.div [ HA.class' "col-sm-6 smallpad" ]
90+
[ HE.button
91+
[ HA.class' "btn btn-primary btn-block"
92+
, HA.id button.id
93+
, HA.createAttribute "ref" "text"
94+
, HA.onClick button.message
95+
]
96+
[ HE.text button.label ]
97+
]
98+
99+
buttons Array Button
100+
buttons =
101+
[ { id: "run", label: "Create 1,000 rows", message: Create 1000 }
102+
, { id: "runlots", label: "Create 10,000 rows", message: Create 10000 }
103+
, { id: "add", label: "Append 1,000 rows", message: AppendOneThousand }
104+
, { id: "update", label: "Update every 10th row", message: UpdateEveryTenth }
105+
, { id: "clear", label: "Clear", message: Clear }
106+
, { id: "swaprows", label: "Swap Rows", message: Swap }
107+
]
108+
109+
renderLazyRow Row Html Message
110110
renderLazyRow row = HE.lazy (Just (show row.id)) renderRow row
111111

112-
renderRow :: Row -> Html Message
113-
renderRow row = HE.tr [ HA.class' { "danger": row.selected }, HA.key (show row.id)] [
114-
HE.td colMd1 [ HE.text (show row.id) ],
115-
HE.td colMd4 [ HE.a [ HA.onClick (Select row.id) ] [ HE.text row.label ] ],
116-
HE.td colMd1 [ HE.a [ HA.onClick (Remove row.id) ] removeIcon ],
117-
spacer
118-
]
112+
renderRow Row Html Message
113+
renderRow row = HE.tr [ HA.class' { "danger": row.selected }, HA.key (show row.id) ]
114+
[ HE.td colMd1 [ HE.text (show row.id) ]
115+
, HE.td colMd4 [ HE.a [ HA.onClick (Select row.id) ] [ HE.text row.label ] ]
116+
, HE.td colMd1 [ HE.a [ HA.onClick (Remove row.id) ] removeIcon ]
117+
, spacer
118+
]
119119

120-
removeIcon :: Array (Html Message)
121-
removeIcon = [
122-
HE.span' [ HA.class' "glyphicon glyphicon-remove", HA.createAttribute "aria-hidden" "true"]
123-
]
120+
removeIcon Array (Html Message)
121+
removeIcon =
122+
[ HE.span' [ HA.class' "glyphicon glyphicon-remove", HA.createAttribute "aria-hidden" "true" ]
123+
]
124124

125-
colMd1 :: Array (NodeData Message)
125+
colMd1 Array (NodeData Message)
126126
colMd1 = [ HA.class' "col-md-1" ]
127127

128-
colMd4 :: Array (NodeData Message)
128+
colMd4 Array (NodeData Message)
129129
colMd4 = [ HA.class' "col-md-4" ]
130130

131-
spacer :: Html Message
131+
spacer Html Message
132132
spacer = HE.td' [ HA.class' "col-md-6" ]
133133

134-
footer :: Html Message
134+
footer Html Message
135135
footer = HE.span' [ HA.class' "preloadicon glyphicon glyphicon-remove", HA.createAttribute "aria-hidden" "true" ]
136136

137-
update :: Update Model Message
137+
update Update Model Message
138138
update model =
139-
case _ of
140-
Create amount -> model /\ [map (\rows -> Just (DisplayCreated rows)) (createRandomNRows amount model.lastID)]
141-
DisplayCreated rows -> F.noMessages (model { lastID = model.lastID + DA.length rows, rows = rows })
139+
case _ of
140+
Create amount model /\ [ map (\rows Just (DisplayCreated rows)) (createRandomNRows amount model.lastID) ]
141+
DisplayCreated rows F.noMessages (model { lastID = model.lastID + DA.length rows, rows = rows })
142142

143-
AppendOneThousand ->
144-
let amount = 1000
145-
in model /\ [map (\rows -> Just (DisplayAppended rows)) (createRandomNRows amount model.lastID)]
146-
DisplayAppended newRows -> F.noMessages (model { lastID = model.lastID + DA.length newRows, rows = model.rows <> newRows })
143+
AppendOneThousand
144+
let
145+
amount = 1000
146+
in
147+
model /\ [ map (\rows → Just (DisplayAppended rows)) (createRandomNRows amount model.lastID) ]
148+
DisplayAppended newRows → F.noMessages (model { lastID = model.lastID + DA.length newRows, rows = model.rows <> newRows })
147149

148-
UpdateEveryTenth -> F.noMessages model { rows = DA.mapWithIndex updateLabel model.rows }
150+
UpdateEveryTenth F.noMessages model { rows = DA.mapWithIndex updateLabel model.rows }
149151

150-
Clear -> F.noMessages (model { rows = [] })
152+
Clear F.noMessages (model { rows = [] })
151153

152-
Swap ->
153-
F.noMessages
154-
(case swapRows model.rows 1 998 of
155-
Nothing -> model
156-
Just swappedRows -> model { rows = swappedRows })
154+
Swap
155+
F.noMessages
156+
( case swapRows model.rows 1 998 of
157+
Nothing → model
158+
Just swappedRows → model { rows = swappedRows }
159+
)
157160

158-
Remove id -> F.noMessages (model { rows = DA.filter (\r -> r.id /= id) model.rows })
161+
Remove id F.noMessages (model { rows = DA.filter (\r r.id /= id) model.rows })
159162

160-
Select id -> F.noMessages (model { rows = map (select id) model.rows })
163+
Select id F.noMessages (model { rows = map (select id) model.rows })
161164

162165
updateLabel index row =
163-
if index `mod` 10 == 0 then
164-
row { label = row.label <> " !!!" }
165-
else
166-
row
166+
if index `mod` 10 == 0 then
167+
row { label = row.label <> " !!!" }
168+
else
169+
row
167170

168171
swapRows arr index otherIndex = do
169-
rowA <- arr !! index
170-
rowB <- arr !! otherIndex
171-
arrA <- DA.updateAt index rowB arr
172-
arrB <- DA.updateAt otherIndex rowA arrA
173-
pure arrB
172+
rowA arr !! index
173+
rowB arr !! otherIndex
174+
arrA DA.updateAt index rowB arr
175+
arrB DA.updateAt otherIndex rowA arrA
176+
pure arrB
174177

175178
select id row
176-
| row.id == id = row { selected = true }
177-
| row.selected = row { selected = false }
178-
| otherwise = row
179+
| row.id == id = row { selected = true }
180+
| row.selected = row { selected = false }
181+
| otherwise = row
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require('./dce-output/Main').main();
1+
require('./output-es/Main').main();

0 commit comments

Comments
 (0)