Skip to content

Fix OCaml type inference in List.fold_left lambda - #19

Merged
SamoraDC merged 1 commit into
mainfrom
claude/fix-ocaml-build-errors-ZJjTT
Dec 12, 2025
Merged

Fix OCaml type inference in List.fold_left lambda#19
SamoraDC merged 1 commit into
mainfrom
claude/fix-ocaml-build-errors-ZJjTT

Conversation

@SamoraDC

Copy link
Copy Markdown
Owner

Add explicit type annotation (pos:position) inside the fold_left lambda. OCaml's type inference determines element type from field access inside lambdas, not from the parameter annotation. Since both position and price_level types have a 'quantity' field, OCaml was inferring price_level based on definition order in types.ml.

The fix: annotate the lambda parameter directly:
List.fold_left (fun acc (pos:position) -> ...)

This ensures OCaml knows pos is of type position when accessing pos.quantity.

Add explicit type annotation (pos:position) inside the fold_left lambda.
OCaml's type inference determines element type from field access inside
lambdas, not from the parameter annotation. Since both position and
price_level types have a 'quantity' field, OCaml was inferring price_level
based on definition order in types.ml.

The fix: annotate the lambda parameter directly:
  List.fold_left (fun acc (pos:position) -> ...)

This ensures OCaml knows pos is of type position when accessing pos.quantity.
@SamoraDC
SamoraDC merged commit bf52c9e into main Dec 12, 2025
4 checks passed
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.

2 participants