Skip to content

Shoyunchap #17

Open
silvitreatment wants to merge 41 commits intoKakadu:masterfrom
silvitreatment:feature/printer
Open

Shoyunchap #17
silvitreatment wants to merge 41 commits intoKakadu:masterfrom
silvitreatment:feature/printer

Conversation

@silvitreatment
Copy link

Implementation of basic miniML interpreter
Author: Rafael Shoyucnhap

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report

(** Binding scope: whether a `let` lives at the top level (no body) or inside an
expression (has body). **)
type var_scope =
| LocalVar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor 'LocalVar' has no documentation attribute

fun fuel ->
match List.assoc_opt x env with
| None -> Error (Unbound_variable x)
| Some cell -> Ok (!cell, fuel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

| Rec ->
(* recursive binding *)
let cell = ref UnitVal in
let env' = (name, cell) :: env in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

let cell = ref UnitVal in
let env' = (name, cell) :: env in
let* v_rhs = eval env' rhs in
cell := v_rhs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

(* builtin fix *)
let builtin_fix : value =
BuiltinVal
(fun f ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using function is recommended

| ClosureVal of name * expression * env
| BuiltinVal of (value -> value eval)

and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report


(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)


(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)

(** Binding scope: whether a `let` lives at the top level (no body) or inside an
expression (has body). **)
type var_scope =
| LocalVar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor 'LocalVar' has no documentation attribute

expression (has body). **)
type var_scope =
| LocalVar
| GlobalVar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor 'GlobalVar' has no documentation attribute

(** Primitive constants. Only ints carry payload; `Unit` is a placeholder for
statements and unused branches. **)
type const =
| Int of int

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor 'Int' has no documentation attribute

fun fuel ->
match List.assoc_opt x env with
| None -> Error (Unbound_variable x)
| Some cell -> Ok (!cell, fuel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

| Rec ->
(* recursive binding *)
let cell = ref UnitVal in
let env' = (name, cell) :: env in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

let cell = ref UnitVal in
let env' = (name, cell) :: env in
let* v_rhs = eval env' rhs in
cell := v_rhs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

(* builtin fix *)
let builtin_fix : value =
BuiltinVal
(fun f ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using function is recommended

| ClosureVal of name * expression * env
| BuiltinVal of (value -> value eval)

and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report

@@ -0,0 +1,72 @@
(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)

@@ -0,0 +1,72 @@
(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)

| ClosureVal of name * expression * env
| BuiltinVal of (value -> value eval)

and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

fun fuel ->
match List.assoc_opt x env with
| None -> Error (Unbound_variable x)
| Some cell -> Ok (!cell, fuel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

| Rec ->
(* recursive binding *)
let cell = ref UnitVal in
let env' = (name, cell) :: env in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

let env' = (name, cell) :: env in
(* Start with a dummy cell so the body of rhs can refer to itself. *)
let* v_rhs = eval env' rhs in
cell := v_rhs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.


(** Mutable cells are kept so `let rec` and `fix` can allocate a placeholder
before evaluating the RHS and later update it. *)
and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report

@@ -0,0 +1,72 @@
(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)

@@ -0,0 +1,72 @@
(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)

| ClosureVal of name * expression * env
| BuiltinVal of (value -> value eval)

and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

fun fuel ->
match List.assoc_opt x env with
| None -> Error (Unbound_variable x)
| Some cell -> Ok (!cell, fuel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

| Rec ->
(* recursive binding *)
let cell = ref UnitVal in
let env' = (name, cell) :: env in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

let env' = (name, cell) :: env in
(* Start with a dummy cell so the body of rhs can refer to itself. *)
let* v_rhs = eval env' rhs in
cell := v_rhs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.


(** Mutable cells are kept so `let rec` and `fix` can allocate a placeholder
before evaluating the RHS and later update it. *)
and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report

@@ -0,0 +1,72 @@
(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)

@@ -0,0 +1,72 @@
(** Copyright 2021-2025, Kakadu and contributors **)

(** SPDX-License-Identifier: LGPL-3.0-or-later **)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First item in file should be a documentation comment with copyright information. For example:
(** Copyright 2021-2022, Winnie Pooh et al. *)

| ClosureVal of name * expression * env
| BuiltinVal of (value -> value eval)

and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

fun fuel ->
match List.assoc_opt x env with
| None -> Error (Unbound_variable x)
| Some cell -> Ok (!cell, fuel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

| Rec ->
(* recursive binding *)
let cell = ref UnitVal in
let env' = (name, cell) :: env in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

let env' = (name, cell) :: env in
(* Start with a dummy cell so the body of rhs can refer to itself. *)
let* v_rhs = eval env' rhs in
cell := v_rhs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.


(** Mutable cells are kept so `let rec` and `fix` can allocate a placeholder
before evaluating the RHS and later update it. *)
and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report

| ClosureVal of name * expression * env
| BuiltinVal of (value -> value eval)

and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

| None -> Error (Unbound_variable x)
| Some cell ->
(* Dereference the placeholder produced by let rec / fix. *)
Ok (!cell, fuel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

| Rec ->
(* recursive binding *)
let cell = ref UnitVal in
let env' = (name, cell) :: env in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

(* Dummy cell lets the RHS call itself (or be captured) during evaluation. *)
let* v_rhs = eval env' rhs in
(* Update the placeholder with the computed value, keeping sharing intact. *)
cell := v_rhs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

(** Environment entries are mutable on purpose: `let rec`/`fix` need a placeholder
cell that is filled after evaluating the RHS, so a `(name * value ref)` list
models that operationally. *)
and env = (name * value ref) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable data structures for teaching purposes is usually discouraged. Replace Hashtables by standard tree-like maps or consider Hash-Array Mapped Tries (HAMT). Use mutable references and mutable structure fields only if it is really required. In all places where it is needed indeed, describe in a comment why it is needed there.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report

@github-actions
Copy link

Документация и тестовое покрытие (86.51%) должны скоро появиться.

https://kakadu.github.io/fp25/docs/Shoyunchap

https://kakadu.github.io/fp25/cov/Shoyunchap

2026-01-16 23:00

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zanuda-linter report

@github-actions
Copy link

Linter report from 2026-01-16 23:01, for mini language Shoyunchap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant