Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening ADT constructor as a module #92

Open
ppolesiuk opened this issue May 7, 2024 · 0 comments
Open

Opening ADT constructor as a module #92

ppolesiuk opened this issue May 7, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ppolesiuk
Copy link
Member

A module could be passed as a named parameter to ADT constructor pattern. Such a construct would define a new local module containing all named parameters. The motivating example is to use encode kind of generative functors known from OCaml or SML, using just named parameters.

data Map Key = Map
  { T
  , empty : {Val} ->[] T Val
  , method add : {Val} -> T Val -> Key -> Val ->[] T Val
  , method find : {Val} -> T Val -> Key ->[] Option Val
  }

(* Functor-like function *)
let makeMap {Key} (compare : Key -> Key ->[] Ord) =
  Map { ... }

(* Functor-like application: creating a new module StrMap that implements maps *)
let (Map { module StrMap }) = make String.compare
@ppolesiuk ppolesiuk added the enhancement New feature or request label May 7, 2024
@ppolesiuk ppolesiuk mentioned this issue Jan 13, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants