From fdd66ee3f20ae5ba6fe774e797b33be74f148049 Mon Sep 17 00:00:00 2001 From: disconcision Date: Thu, 7 Nov 2024 15:02:38 -0500 Subject: [PATCH] add sum type constructor ap form for type definitions. populate load slots with MVU checkpoints --- src/hazel/Grammar.re | 4 ++ src/web/Data.re | 138 ++++++++++++++++++++++++++++++++++++++++++- src/web/Store.re | 32 ++++++---- 3 files changed, 160 insertions(+), 14 deletions(-) diff --git a/src/hazel/Grammar.re b/src/hazel/Grammar.re index 73605859..ac9af73c 100644 --- a/src/hazel/Grammar.re +++ b/src/hazel/Grammar.re @@ -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"), @@ -51,6 +53,8 @@ module Typ = { p(operand), //Sum type p(~a=L, seq([typ, op("+"), typ])), + //Constructor def for sums + p(cons_ap), ]; }; diff --git a/src/web/Data.re b/src/web/Data.re index 14504d37..e632d448 100644 --- a/src/web/Data.re +++ b/src/web/Data.re @@ -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 = {||}; diff --git a/src/web/Store.re b/src/web/Store.re index 1cc4928d..96123867 100644 --- a/src/web/Store.re +++ b/src/web/Store.re @@ -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)]