Skip to content

Commit

Permalink
❗ [modify]: Better 'let' layout for demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolyp committed Sep 19, 2023
1 parent 1f21ae8 commit 2974db6
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 19 deletions.
3 changes: 2 additions & 1 deletion fluid/example/slicing/array/dims.expect.fld
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
let (x, y) = ⸨(⸨3⸩, ⸨3⸩)⸩;
yss = ⸨[|0|(i, j) in (x, y)|]⸩ in dims yss
yss = ⸨[|0|(i, j) in (x, y)|]⸩ in
dims yss
3 changes: 2 additions & 1 deletion fluid/example/slicing/array/lookup.expect.fld
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
let xs = [[1, 4, 8], [3, 2, 17], [0, ⸨14⸩, 6]];
ys = [|nth2 i j xs|(i, j) in (3, 3)|] in ys ! ((3, 2))
ys = [|nth2 i j xs|(i, j) in (3, 3)|] in
ys ! ((3, 2))
3 changes: 2 additions & 1 deletion fluid/example/slicing/convolution/edgeDetect.expect.fld
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let edgeDetect = [[⸨0⸩, ⸨1⸩, ⸨0⸩], [⸨1⸩, ⸨-4⸩, ⸨1⸩], [⸨0⸩, ⸨1⸩, ⸨0⸩]];
kernel = [|nth2 i j edgeDetect|(i, j) in (⸨3⸩, ⸨3⸩)|];
image' = [[⸨15⸩, ⸨13⸩, 6, 9, 16], [⸨12⸩, 5, 15, 4, 13], [14, 9, 20, 8, 1], [4, 10, 3, 7, 19], [3, 11, 15, 2, 9]];
image = [|nth2 i j image'|(i, j) in (5, 5)|] in convolve image kernel extend
image = [|nth2 i j image'|(i, j) in (5, 5)|] in
convolve image kernel extend
3 changes: 2 additions & 1 deletion fluid/example/slicing/convolution/emboss.expect.fld
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let emboss = [[-2, -1, 0], [-1, ⸨1⸩, ⸨1⸩], [0, ⸨1⸩, ⸨2⸩]];
filter = [|nth2 i j emboss|(i, j) in (⸨3⸩, ⸨3⸩)|];
image' = [[⸨15⸩, ⸨13⸩, 6, 9, 16], [⸨12⸩, ⸨5⸩, 15, 4, 13], [14, 9, 20, 8, 1], [4, 10, 3, 7, 19], [3, 11, 15, 2, 9]];
image = [|nth2 i j image'|(i, j) in (5, 5)|] in convolve image filter zero
image = [|nth2 i j image'|(i, j) in (5, 5)|] in
convolve image filter zero
3 changes: 2 additions & 1 deletion fluid/example/slicing/convolution/gaussian.expect.fld
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let gaussian = [[1, 4, 1], [4, ⸨16⸩, ⸨4⸩], [1, ⸨4⸩, ⸨1⸩]];
filter = [|nth2 i j gaussian|(i, j) in (⸨3⸩, ⸨3⸩)|];
image' = [[⸨15⸩, ⸨13⸩, 6, 9, 16], [⸨12⸩, ⸨5⸩, 15, 4, 13], [14, 9, 20, 8, 1], [4, 10, 3, 7, 19], [3, 11, 15, 2, 9]];
image = [|nth2 i j image'|(i, j) in (5, 5)|] in convolve image filter zero
image = [|nth2 i j image'|(i, j) in (5, 5)|] in
convolve image filter zero
3 changes: 2 additions & 1 deletion fluid/example/slicing/dict/difference.expect.fld
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
let e = ⸨{|"a" := 5, "a" ++ "b" := 6|}⸩;
f = ⸨{|"ab" := 12|}⸩ in dict_difference e f
f = ⸨{|"ab" := 12|}⸩ in
dict_difference e f
3 changes: 2 additions & 1 deletion fluid/example/slicing/dict/get.expect.fld
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
let d = {|"a" := 5, "a" ++ "b" := {fst : 6,
snd : ⸨0⸩}|} in dict_get "a" d * dict_get "ab" d.snd
snd : ⸨0⸩}|} in
dict_get "a" d * dict_get "ab" d.snd
3 changes: 2 additions & 1 deletion fluid/example/slicing/dict/intersectionWith.expect.fld
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dict_intersectionWith (let x = ⸨2⸩ in (fun n m = (n + m) * x)) {|"a" := 5, "b" := ⸨6⸩, "c" := ⸨3⸩|} {|"b" := ⸨-6⸩, "c" := ⸨7⸩|}
dict_intersectionWith (let x = ⸨2⸩ in
(fun n m = (n + m) * x)) {|"a" := 5, "b" := ⸨6⸩, "c" := ⸨3⸩|} {|"b" := ⸨-6⸩, "c" := ⸨7⸩|}
6 changes: 4 additions & 2 deletions fluid/example/slicing/dict/map.expect.fld
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
let incHead = let x = ⸨3⸩ in (fun xs = head xs + x);
let incHead = let x = ⸨3⸩ in
(fun xs = head xs + x);
d = {|"a" := [⸨5⸩, 6], "b" := [⸨9⸩, 10], "c" := [3, 4]|};
e = {|"c" := []|};
d' = dict_map incHead (dict_difference d e) in dict_get "a" d' + dict_get "b" d'
d' = dict_map incHead (dict_difference d e) in
dict_get "a" d' + dict_get "b" d'
3 changes: 2 additions & 1 deletion fluid/example/slicing/filter.expect.fld
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
let filter p [] = [];
filter p (x : xs) = let ys = filter p xs in if p x then (x ⸨:⸩ ys) else ys in
filter p (x : xs) = let ys = filter p xs in
if p x then (x ⸨:⸩ ys) else ys in
filter ((<) ⸨5⸩) [⸨8⸩, 4, 7, 3]
3 changes: 2 additions & 1 deletion fluid/example/slicing/list-comp-1.expect.fld
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ let data = [{year : 2013, country : "China", energyType : "Bio", output : 6.2}
, {year : 2013, country : "China", energyType : ⸨"Hydro"⸩, output : 260}
, {year : 2013, country : "China", energyType : "Solar", output : 19.9}
, {year : 2013, country : "China", energyType : "Wind", output : 91}
] in ⸨[row.output|type <- ["Bio", ⸨"Hydro"⸩, "Solar", "Wind"], row <- data, row.energyType == type]⸩
] in
⸨[row.output|type <- ["Bio", ⸨"Hydro"⸩, "Solar", "Wind"], row <- data, row.energyType == type]⸩
3 changes: 2 additions & 1 deletion fluid/example/slicing/list-comp-2.expect.fld
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ let data = [{year : 2013, country : "China", energyType : "Bio", output : 6.2}
, {year : 2013, country : "China", energyType : "Hydro", output : 260}
, {year : 2013, country : "China", energyType : ⸨"Solar"⸩, output : 19.9}
, {year : 2013, country : "China", energyType : "Wind", output : 91}
] in ⸨[row.output|type <- ["Bio", "Hydro", ⸨"Solar"⸩, "Wind"], row <- data, row.energyType == type]⸩
] in
⸨[row.output|type <- ["Bio", "Hydro", ⸨"Solar"⸩, "Wind"], row <- data, row.energyType == type]⸩
3 changes: 2 additions & 1 deletion fluid/example/slicing/section-5-example-1.expect.fld
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ let data = [{energyType : "Bio", output : 6.2}
, {energyType : "Wind", output : 91}
, {energyType : "Geo", output : 14.4}
];
output = ⸨[row.output|type <- [⸨"Hydro"⸩, "Solar", "Geo"], row <- data, row.energyType == type]⸩ in map (fun x = floor ((x / sum output) * 100)) output
output = ⸨[row.output|type <- [⸨"Hydro"⸩, "Solar", "Geo"], row <- data, row.energyType == type]⸩ in
map (fun x = floor ((x / sum output) * 100)) output
3 changes: 2 additions & 1 deletion fluid/example/slicing/section-5-example-2.expect.fld
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ let data = [{energyType : "Bio", output : 6.2}
, {energyType : "Wind", output : 91}
, {energyType : "Geo", output : ⸨14.4⸩}
];
output = [row.output|type <- ["Hydro", "Solar", "Geo"], row <- data, row.energyType == type] in map (fun x = floor ((x / sum output) * ⸨100⸩)) output
output = [row.output|type <- ["Hydro", "Solar", "Geo"], row <- data, row.energyType == type] in
map (fun x = floor ((x / sum output) * ⸨100⸩)) output
3 changes: 2 additions & 1 deletion fluid/example/slicing/section-5-example-3.expect.fld
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ let data = [{energyType : "Bio", output : 6.2}
, {energyType : "Wind", output : 91}
, {energyType : ⸨"Geo"⸩, output : 14.4}
];
output = ⸨[row.output|type <- ["Hydro", "Solar", ⸨"Geo"⸩], row <- data, row.energyType == type]⸩ in map (fun x = floor ((x / sum output) * 100)) output
output = ⸨[row.output|type <- ["Hydro", "Solar", ⸨"Geo"⸩], row <- data, row.energyType == type]⸩ in
map (fun x = floor ((x / sum output) * 100)) output
5 changes: 2 additions & 3 deletions src/Pretty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ instance Ann a => Pretty (Expr a) where
pretty (Record ann xss) = (highlightIf ann $ curlyBraces (prettyOperator (.-.) xss))
pretty (Dictionary ann sss) = (highlightIf ann $ dictBrackets (pretty sss))
pretty (Matrix ann e (x × y) e') =
( highlightIf ann $ arrayBrackets
highlightIf ann $ arrayBrackets
( pretty e .<>. text str.bar .<>. parentheses (text x .<>. text str.comma .<>. text y)
.<>. text str.in_
.<>. pretty e'
)
)
pretty (Lambda cs) = parentheses (text str.fun .<>. pretty cs)
pretty (Project s x) = pretty s .<>. text str.dot .<>. text x
pretty (App s s') = prettyAppChain (App s s')
Expand All @@ -154,7 +153,7 @@ instance Ann a => Pretty (Expr a) where
pretty (ListNonEmpty ann e l) = ((highlightIf ann $ text str.lBracket)) .<>. pretty e .<>. pretty l
pretty (ListEnum s s') = brackets (pretty s .<>. text str.ellipsis .<>. pretty s')
pretty (ListComp ann s qs) = (highlightIf ann $ brackets (pretty s .<>. text str.bar .<>. pretty qs))
pretty (Let ds s) = text str.let_ .<>. pretty ds .<>. text str.in_ .<>. pretty s
pretty (Let ds s) = (text str.let_ .<>. pretty ds .<>. text str.in_) .-. pretty s
pretty (LetRec h s) = (text str.let_ .<>. pretty (First h) .<>. text str.in_) .-. pretty s

prettyOperator :: forall a. Ann a => (Doc -> Doc -> Doc) -> List (Bind (Expr a)) -> Doc
Expand Down

0 comments on commit 2974db6

Please sign in to comment.