Skip to content

Commit

Permalink
add sum type constructor ap form for type definitions. populate load …
Browse files Browse the repository at this point in the history
…slots with MVU checkpoints
  • Loading branch information
disconcision committed Nov 7, 2024
1 parent 2d450c6 commit fdd66ee
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/hazel/Grammar.re
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module Typ = {
let sort = Sort.of_str("Typ");
let typ = nt(sort);

let cons_ap = seq([typ, brc(L, "("), comma_sep(typ), brc(R, ")")]);

let operand =
alt([
// c("Int"),
Expand All @@ -51,6 +53,8 @@ module Typ = {
p(operand),
//Sum type
p(~a=L, seq([typ, op("+"), typ])),
//Constructor def for sums
p(cons_ap),
];
};

Expand Down
138 changes: 137 additions & 1 deletion src/web/Data.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,140 @@ let update: (Model, Action) -> Model =
in
update(init, StampEmoji(1, 1))|};

//fun ((grid, selectedEmoji, emojiList), action) ->
let ep0 = {|type Emoji = None + Smile + Laugh in
type Model = Emoji in
type Action = StampEmoji in
let init: Model = None in
let update: (Model, Action) -> Model =
fun (model, action) ->
case action
| StampEmoji => Smile
in
update(init, StampEmoji)|};

let ep1 = {|type Emoji = None + Smile + Laugh in
type Model = (Emoji, Emoji) in
type Action =
StampEmoji
+ SelectEmoji(Emoji)
in
let init: Model = (None, Smile) in
let update: (Model, Action) -> Model =
fun ((canvas, selectedEmoji), action) ->
case action
| SelectEmoji(emoji) =>
(canvas, emoji)
| StampEmoji =>
(selectedEmoji, selectedEmoji)
in update(init, SelectEmoji(Laugh))|};

let ep2 = {|type Emoji = None + Smile + Laugh in
type Model = ([Emoji],Emoji) in
type Action =
StampEmoji(Int)
+ SelectEmoji(Emoji)
in
let init: Model = ([None, None, None], Smile) in
let update: (Model, Action) -> Model =
fun ((canvas, selectedEmoji), action) ->
case action
| StampEmoji(index) =>
let new_canvas =
List.mapi(
(fun (i, currentEmoji) ->
if i == index
then selectedEmoji
else currentEmoji),
canvas)
in (new_canvas, selectedEmoji)
| SelectEmoji(emoji) =>
(canvas, emoji)
in
update(init, StampEmoji(2))|};

let ep3 = {|type Emoji = None + Smile + Laugh in
type Model = ([Emoji],Emoji) in
type Action =
StampEmoji(Int)
+ ClearCell(Int)
+ SelectEmoji(Emoji)
in
let init: Model = ([Smile, None, None], Smile) in
let update_canvas =
fun (index, emoji, canvas) ->
List.mapi(
(fun (i, currentEmoji) ->
if i == index
then emoji
else currentEmoji),
canvas)
in
let update: (Model, Action) -> Model =
fun ((canvas, selectedEmoji), action) ->
case action
| StampEmoji(index) =>
(update_canvas(index, selectedEmoji, canvas), selectedEmoji)
| ClearCell(index) =>
(update_canvas(index, None, canvas), selectedEmoji)
| SelectEmoji(emoji) =>
(canvas, emoji)
in
update(init, ClearCell(0))|};

let ep4 = {|type Emoji = None + Smile + Laugh in
type Model = ([[Emoji]],Emoji) in
type Action =
StampEmoji(Int, Int)
+ ClearCell(Int, Int)
+ SelectEmoji(Emoji)
in
let init: Model = (
[
[None, None, None],
[None, None, None],
[None, None, None]
],
Smile)
in
let update_row =
fun (target_col, emoji, row) ->
List.mapi(
(fun (col_index, col) ->
if col_index == target_col then emoji else col),
row) in
let update_canvas =
fun (target_row, target_col, emoji, canvas) ->
List.mapi(
(fun (row_index, row) ->
if row_index == target_row
then update_row(target_col, emoji, row)
else row),
canvas)
in
let update: (Model, Action) -> Model =
fun ((canvas, selectedEmoji), action) ->
case action
| StampEmoji(row, col) =>
(update_canvas(row, col, selectedEmoji, canvas), selectedEmoji)
| ClearCell(row, col) =>
(update_canvas(row, col, None, canvas), selectedEmoji)
| SelectEmoji(emoji) =>
(canvas, emoji)
in
update(init, StampEmoji(1, 1)) |};

//let ep5 = {||};
32 changes: 19 additions & 13 deletions src/web/Store.re
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,25 @@ let save_syntax_key: int => string =
let save_syntax = (save_idx: int, z: Zipper.t) =>
LocalStorage.set(save_syntax_key(save_idx), z |> serialize);

let tasks = []; // Data.t0_transcribe,
// Data.t0_modify,
// Data.t1_transcribe,
// Data.t1_modify,
// Data.t2_transcribe,
// Data.t2_modify,
// Data.emoji_paint,
// Data.t3_transcribe,
// Data.t3_modify,
// (("case 7\n| x => 7")),
// (("let (a, b) =\n(8*9<6, 17==6) in\n(a,(a, b))")),

// (("let f = fun z -> 9 in f(9)")),
let tasks = [
Data.ep0,
Data.ep1,
Data.ep2,
Data.ep3,
Data.ep4,
Data.t0_transcribe,
Data.t1_transcribe,
Data.t2_transcribe,
Data.t3_transcribe,
// Data.emoji_paint,
// Data.t0_modify,
// Data.t1_modify,
// Data.t2_modify,
// Data.t3_modify,
// (("case 7\n| x => 7")),
// (("let (a, b) =\n(8*9<6, 17==6) in\n(a,(a, b))")),
// (("let f = fun z -> 9 in f(9)")),
];

let editor_defaults =
[serialize(Zipper.empty)]
Expand Down

0 comments on commit fdd66ee

Please sign in to comment.