Skip to content

C#_strange_Kuznetsov#28

Open
f1i3g3 wants to merge 84 commits into
Kakadu:masterfrom
f1i3g3:c-sharp-strange
Open

C#_strange_Kuznetsov#28
f1i3g3 wants to merge 84 commits into
Kakadu:masterfrom
f1i3g3:c-sharp-strange

Conversation

@f1i3g3
Copy link
Copy Markdown

@f1i3g3 f1i3g3 commented Mar 6, 2026

Added my version of C# language's subset (which is similar to miniML).
Supported:

  • Basic value types (ints, bools, chars, strings) + printing function
  • Basic expressions
  • Statements (if, for, while)
  • Parser & pretty printer (with cram & quickcheck tests)
  • Monadic typecheck
  • Monadic interpreter

f1i3g3 added 30 commits March 1, 2026 18:07
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: Dmitri <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Copy link
Copy Markdown

@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

open Stdio

type opts =
{ mutable dump_parse_tree : bool
Copy link
Copy Markdown

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.

Comment thread CSharpStrange_Kuznetsov/bin/REPL.ml
type opts =
{ mutable dump_parse_tree : bool
; mutable file_path : string option
; mutable eval : bool
Copy link
Copy Markdown

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.

Comment thread CSharpStrange_Kuznetsov/bin/REPL.ml Outdated
match interpret_program ast with
| Ok (Some v) -> printf "Result: %s\n" (show_value v)
| Ok None -> printf "Result: void\n"
| Error _ -> failwith (sprintf "Interpretation error"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using failwith (or assert false) usually is a clue that a corner case is not being handled properly. To report errors we recommend using error monad instead. In princliple, these construction are OK for temporary work-in-progress code, but in release they should be eliminated

Comment thread CSharpStrange_Kuznetsov/bin/REPL.ml Outdated
| Ok (Some v) -> printf "Result: %s\n" (show_value v)
| Ok None -> printf "Result: void\n"
| Error _ -> failwith (sprintf "Interpretation error"))
| Error msg -> failwith (sprintf "Failed to parse file: %s" msg)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using failwith (or assert false) usually is a clue that a corner case is not being handled properly. To report errors we recommend using error monad instead. In princliple, these construction are OK for temporary work-in-progress code, but in release they should be eliminated

f1i3g3 added 20 commits March 9, 2026 17:32
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
@github-actions
Copy link
Copy Markdown

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

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

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

2026-03-16 21:39

Copy link
Copy Markdown

@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

Comment thread CSharpStrange_Kuznetsov/bin/REPL.ml Outdated
| Error e -> failwith (sprintf "Interpretation error: %s" (show_error e)))
| None, Ok _ -> failwith "Interpretation error: Main method not found"
| _, Error e -> failwith (sprintf "Typecheck error: %s" (show_error e))))
| Error msg -> failwith (sprintf "Parser error: Failed to parse file: %s" msg)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using failwith (or assert false) usually is a clue that a corner case is not being handled properly. To report errors we recommend using error monad instead. In princliple, these construction are OK for temporary work-in-progress code, but in release they should be eliminated

gen_expr_no_assign env var_type >>= fun e -> return (EBinOp (OpAssign, EId id, e)))

(* Binary operations *)
and gen_binop_expr env expected_type =
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using function is recommended

| _ -> gen_expr_no_assign env expected_type

(* Binary operations without assignment *)
and gen_binop_expr_no_assign env expected_type =
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using function is recommended

; (4, gen_funcall env TypeVoid >>= fun e -> return (SExpr e))
; ( 2
, if
List.length (List.filter (fun (_, (_, ret)) -> ret <> TypeVoid) env.functions)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bad measurement of a list (with non-negative size)
Between 'List.length
(List.filter (fun (, (, ret)) -> ret <> TypeVoid) env.functions)' and '
0'.

with
| Ok expr' ->
let code_str' = expr_to_code_string expr' in
if code_str = code_str'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Executing 'if ... then true' smells bad

with
| Ok prog' ->
let code_str' = program_to_code_string prog' in
if code_str = code_str'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Executing 'if ... then true' smells bad

Angstrom.parse_string ~consume:Angstrom.Consume.All Parser.parse_ops code_str
with
| Ok expr' ->
if compare_expr_structure expr expr'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Executing 'if ... then true' smells bad

f1i3g3 added 2 commits March 16, 2026 21:58
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Signed-off-by: f1i3g3 <dmitrvlkuznetsov@gmail.com>
Copy link
Copy Markdown

@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
Copy Markdown

Linter report from 2026-03-16 22:13, for mini language CSharpStrange_Kuznetsov

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