Skip to content
Discussion options

You must be logged in to vote

Hi @metaleap. Thanks for your interest in this project!

Here's how you implement your function in MLstruct:

class Nil
class Cons[A]: { h: A; t: List[A] }
type List[A] = Cons[A] | Nil

def concat: List['a] -> List['a] -> List['a]
rec def concat x y = case x of
  Nil -> y,
  Cons -> Cons { h = x.h; t = concat x.t y }

rec def flatten x = case x of
  Nil -> Nil{},
  Cons -> concat (flatten x.h) (flatten x.t),
  _ -> Cons { h = x; t = Nil{} }

You can try it in the web demo or in the project's diff-tests, which yield the following output:

class Nil
class Cons[A]: { h: A; t: List[A] }
type List[A] = Cons[A] | Nil
//│ Defined class Nil
//│ Defined class Cons[+A]
//│ Defined type alias List[+A]

def

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LPTK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2 on April 23, 2025 02:20.