Skip to content

Commit

Permalink
Update translation of Seq constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmendez committed Jan 31, 2024
1 parent ad08ef4 commit 9a66741
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private def _tailrec_foldl_while ( A : Type ) ( B : Type ) (sequence : List (
(next : B -> A -> B) (condition : B -> A -> Bool) : B :=
match sequence with
| List.nil => current
| (head) +: (tail) =>
| (head) :: (tail) =>
if (not (condition (current) (head) ) )
then current
else _tailrec_foldl_while ( A ) ( B ) (tail) (next (current) (head) ) (next) (condition)
Expand Down Expand Up @@ -64,7 +64,7 @@ private def _tailrec_foldl ( A : Type ) ( B : Type ) (sequence : List ( A ) )
(next : B -> A -> B) : B :=
match sequence with
| List.nil => current
| (head) +: (tail) =>
| (head) :: (tail) =>
_tailrec_foldl ( A ) ( B ) (tail) (next (current) (head) ) (next)


Expand All @@ -90,7 +90,7 @@ namespace Range
private def _tailrec_range (non_negative_number : Int) (sequence : List ( Int ) ) : List ( Int ) :=
match non_negative_number with
| Succ_ (k) =>
_tailrec_range (k) ( (k) +: (sequence) )
_tailrec_range (k) ( (k) :: (sequence) )
| _otherwise => sequence


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LeanClassConstructorBlockTranslator
_tc .lean_new_line + _get_initial_spaces (beginning) + _two_spaces +
_tc .lean_default_constructor_name +
_tc .lean_space +
_tc .lean_constructor_symbol +
_tc .lean_list_constructor_symbol +
_tc .lean_new_line + _get_initial_spaces (beginning) + _four_spaces +
functions .mkString (_tc .lean_new_line + _get_initial_spaces (beginning) + _four_spaces) +
_tc .lean_new_line +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ trait LeanClassConstructorBlockTranslator
_tc .lean_new_line + _get_initial_spaces (beginning) + _two_spaces +
_tc .lean_default_constructor_name +
_tc .lean_space +
_tc .lean_constructor_symbol +
_tc .lean_list_constructor_symbol +
_tc .lean_new_line + _get_initial_spaces (beginning) + _four_spaces +
functions .mkString (_tc .lean_new_line + _get_initial_spaces (beginning) + _four_spaces) +
_tc .lean_new_line +
Expand Down Expand Up @@ -1226,7 +1226,7 @@ trait TranslationConstantToLean

lazy val lean_product_type_symbol = "*"

lazy val lean_constructor_symbol = "::"
lazy val lean_list_constructor_symbol = "::"

lazy val lean_lambda_arrow_symbol = "=>"

Expand Down Expand Up @@ -1626,8 +1626,8 @@ trait TranslationConstantToLean
Tuple2 (soda_constant .or_reserved_word , lean_or_symbol) ,
Tuple2 (soda_constant .tail_recursion_annotation , lean_empty_string) ,
Tuple2 (soda_constant .override_annotation , lean_empty_string) ,
Tuple2 (soda_constant .new_annotation , lean_empty_string)

Tuple2 (soda_constant .new_annotation , lean_empty_string) ,
Tuple2 (soda_constant .seq_constructor_symbol , lean_list_constructor_symbol)
)

lazy val type_translation : Seq [Tuple2 [String, String] ] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TranslationConstantToLean

lean_product_type_symbol = "*"

lean_constructor_symbol = "::"
lean_list_constructor_symbol = "::"

lean_lambda_arrow_symbol = "=>"

Expand Down Expand Up @@ -456,8 +456,8 @@ class TranslationConstantToLean
Tuple2 (soda_constant .or_reserved_word , lean_or_symbol) ,
Tuple2 (soda_constant .tail_recursion_annotation , lean_empty_string) ,
Tuple2 (soda_constant .override_annotation , lean_empty_string) ,
Tuple2 (soda_constant .new_annotation , lean_empty_string)

Tuple2 (soda_constant .new_annotation , lean_empty_string) ,
Tuple2 (soda_constant .seq_constructor_symbol , lean_list_constructor_symbol)
)

type_translation : Seq [Tuple2 [String] [String] ] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,8 @@ trait TranslationConstantToScala

lazy val scala_or_symbol = "||"

lazy val scala_empty_list_reserved_word = "Nil"

lazy val scala_tail_recursion_annotation_translation =
"import scala.annotation.tailrec\n @tailrec final"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class TranslationConstantToScala

scala_or_symbol = "||"

scala_empty_list_reserved_word = "Nil"

scala_tail_recursion_annotation_translation =
"import scala.annotation.tailrec\n @tailrec final"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ trait SodaConstant

lazy val list_constructor_unicode_symbol = "\u2237"

lazy val seq_constructor_symbol = "+:"

lazy val documentation_comment_opening_symbol = "/**"

lazy val comment_opening_symbol = "/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class SodaConstant

list_constructor_unicode_symbol = "\u2237"

seq_constructor_symbol = "+:"

documentation_comment_opening_symbol = "/**"

comment_opening_symbol = "/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private def _tailrec_foldl_while ( A : Type ) ( B : Type ) (sequence : List (
(next : B -> A -> B) (condition : B -> A -> Bool) : B :=
match sequence with
| List.nil => current
| (head) +: (tail) =>
| (head) :: (tail) =>
if (not (condition (current) (head) ) )
then current
else _tailrec_foldl_while ( A ) ( B ) (tail) (next (current) (head) ) (next) (condition)
Expand Down Expand Up @@ -64,7 +64,7 @@ private def _tailrec_foldl ( A : Type ) ( B : Type ) (sequence : List ( A ) )
(next : B -> A -> B) : B :=
match sequence with
| List.nil => current
| (head) +: (tail) =>
| (head) :: (tail) =>
_tailrec_foldl ( A ) ( B ) (tail) (next (current) (head) ) (next)


Expand All @@ -90,7 +90,7 @@ namespace Range
private def _tailrec_range (non_negative_number : Int) (sequence : List ( Int ) ) : List ( Int ) :=
match non_negative_number with
| Succ_ (k) =>
_tailrec_range (k) ( (k) +: (sequence) )
_tailrec_range (k) ( (k) :: (sequence) )
| _otherwise => sequence


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,35 @@ class MicroTranslatorToLeanSpec ()
check (
obtained := instance .translate (
"as_list (a : Boolean) : List [Boolean] =" +
"\n (a) :: (Nil)" +
"\n a :: Nil" +
"\n"
)
) (
expected := "" +
" def as_list (a : Bool) : List ( Bool ) :=" +
"\n (a) :: (List.nil)" +
"\n a :: List.nil" +
"\n" +
"\n"
)
)

test ("Lean translation of types 2") (
check (
obtained := instance .translate (
"as_seq (a : Boolean) : Seq [Boolean] =" +
"\n (a) +: (Nil)" +
"\n"
)
) (
expected := "" +
" def as_seq (a : Bool) : List ( Bool ) :=" +
"\n (a) :: (List.nil)" +
"\n" +
"\n"
)
)

test ("Lean translation of types 3") (
check (
obtained := instance .translate (
"class Example" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,35 @@ case class MicroTranslatorToLeanSpec ()
check (
obtained = instance .translate (
"as_list (a : Boolean) : List [Boolean] =" +
"\n (a) :: (Nil)" +
"\n a :: Nil" +
"\n"
)
) (
expected = "" +
" def as_list (a : Bool) : List ( Bool ) :=" +
"\n (a) :: (List.nil)" +
"\n a :: List.nil" +
"\n" +
"\n"
)
)

test ("Lean translation of types 2") (
check (
obtained = instance .translate (
"as_seq (a : Boolean) : Seq [Boolean] =" +
"\n (a) +: (Nil)" +
"\n"
)
) (
expected = "" +
" def as_seq (a : Bool) : List ( Bool ) :=" +
"\n (a) :: (List.nil)" +
"\n" +
"\n"
)
)

test ("Lean translation of types 3") (
check (
obtained = instance .translate (
"class Example" +
Expand Down

0 comments on commit 9a66741

Please sign in to comment.