From a268b8e66fbb5ad51e053bbb9a334a6460602aed Mon Sep 17 00:00:00 2001
From: Eduardo Julian
Date: Thu, 10 May 2018 21:42:17 -0400
Subject: - Some improvements and fixes for stdlib.
---
stdlib/source/lux/data/format/json.lux | 5 +--
stdlib/source/lux/io.lux | 4 +++
stdlib/source/lux/macro/poly.lux | 62 ++++++++--------------------------
stdlib/source/lux/macro/poly/eq.lux | 12 +++----
stdlib/source/lux/macro/poly/json.lux | 33 +++++++++---------
stdlib/source/lux/test.lux | 5 +--
stdlib/test/tests.lux | 6 ++--
7 files changed, 50 insertions(+), 77 deletions(-)
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux
index c4dd43a1c..d960830db 100644
--- a/stdlib/source/lux/data/format/json.lux
+++ b/stdlib/source/lux/data/format/json.lux
@@ -19,10 +19,7 @@
(dictionary ["dict" unordered #+ Dict])))
[macro #+ Monad with-gensyms]
(macro ["s" syntax #+ syntax:]
- [code]
- [poly #+ poly:])
- (lang [type])
- ))
+ [code])))
(do-template [ ]
[(type: #export )]
diff --git a/stdlib/source/lux/io.lux b/stdlib/source/lux/io.lux
index 72307c301..d35584fd1 100644
--- a/stdlib/source/lux/io.lux
+++ b/stdlib/source/lux/io.lux
@@ -49,6 +49,10 @@
(All [a] (-> (IO a) a))
(action (:! Bottom [])))
+(def: #export (exit code)
+ (-> Int (IO Bottom))
+ (io ("lux io exit" code)))
+
## Process
(type: #export (Process a)
(IO (Error a)))
diff --git a/stdlib/source/lux/macro/poly.lux b/stdlib/source/lux/macro/poly.lux
index f3537d6f0..54a856463 100644
--- a/stdlib/source/lux/macro/poly.lux
+++ b/stdlib/source/lux/macro/poly.lux
@@ -115,43 +115,6 @@
(#e.Success [[_ inputs'] output])
(#e.Success [[env inputs'] [g!var output]])))))
-(do-template [ ]
- [(def: #export
- (Poly Top)
- (do p.Monad
- [headT any]
- (case (type.un-name headT)
-
- (wrap [])
-
- _
- (p.fail ($_ text/compose "Not " " type: " (type.to-text headT))))))]
-
- [bool "Bool" (#.Primitive "#Bool" #.Nil)]
- [nat "Nat" (#.Primitive "#Nat" #.Nil)]
- [int "Int" (#.Primitive "#Int" #.Nil)]
- [deg "Deg" (#.Primitive "#Deg" #.Nil)]
- [frac "Frac" (#.Primitive "#Frac" #.Nil)]
- [text "Text" (#.Primitive "#Text" #.Nil)]
- )
-
-(def: #export basic
- (Poly Type)
- (do p.Monad
- [headT any]
- (case (run headT ($_ p.either
- bool
- nat
- int
- deg
- frac
- text))
- (#e.Error error)
- (p.fail error)
-
- (#e.Success _)
- (wrap headT))))
-
(do-template [ ]
[(def: #export ( poly)
(All [a] (-> (Poly a) (Poly a)))
@@ -231,16 +194,21 @@
(p.fail ($_ text/compose "Non-application type: " (type.to-text headT)))
(local (#.Cons funcT paramsT) poly))))
-(def: #export (this expected)
- (-> Type (Poly Top))
- (do p.Monad
- [actual any]
- (if (type/= expected actual)
- (wrap [])
- (p.fail ($_ text/compose
- "Types do not match." "\n"
- "Expected: " (type.to-text expected) "\n"
- " Actual: " (type.to-text actual))))))
+(do-template [ ]
+ [(def: #export ( expected)
+ (-> Type (Poly Top))
+ (do p.Monad
+ [actual any]
+ (if ( expected actual)
+ (wrap [])
+ (p.fail ($_ text/compose
+ "Types do not match." "\n"
+ "Expected: " (type.to-text expected) "\n"
+ " Actual: " (type.to-text actual))))))]
+
+ [this type/=]
+ [like check.checks?]
+ )
(def: (adjusted-idx env idx)
(-> Env Nat Nat)
diff --git a/stdlib/source/lux/macro/poly/eq.lux b/stdlib/source/lux/macro/poly/eq.lux
index 6206c9861..ec120e0e1 100644
--- a/stdlib/source/lux/macro/poly/eq.lux
+++ b/stdlib/source/lux/macro/poly/eq.lux
@@ -46,12 +46,12 @@
))))]
[(poly.this Top) (function ((~ g!_) (~ g!_) (~ g!_)) true)]
- [poly.bool bool.Eq]
- [poly.nat number.Eq]
- [poly.int number.Eq]
- [poly.deg number.Eq]
- [poly.frac number.Eq]
- [poly.text text.Eq]))
+ [(poly.like Bool) bool.Eq]
+ [(poly.like Nat) number.Eq]
+ [(poly.like Int) number.Eq]
+ [(poly.like Deg) number.Eq]
+ [(poly.like Frac) number.Eq]
+ [(poly.like Text) text.Eq]))
## Composite types
(~~ (do-template [ ]
[(do @
diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux
index 2e288648e..44075647d 100644
--- a/stdlib/source/lux/macro/poly/json.lux
+++ b/stdlib/source/lux/macro/poly/json.lux
@@ -6,8 +6,9 @@
["p" parser "p/" Monad])
(data [bool]
[bit]
- [text "text/" Eq Monoid]
- (text ["l" lexer])
+ [text "text/" Eq]
+ (text ["l" lexer]
+ format)
[number "frac/" Codec "nat/" Codec]
maybe
["e" error]
@@ -87,11 +88,11 @@
))))]
[(poly.this Top) (function ((~ g!_) (~ (code.symbol ["" "0"]))) #//.Null)]
- [poly.bool (|>> #//.Boolean)]
- [poly.nat (:: (~! ..Codec) (~' encode))]
- [poly.int (:: (~! ..Codec) (~' encode))]
- [poly.frac (|>> #//.Number)]
- [poly.text (|>> #//.String)])
+ [(poly.like Bool) (|>> #//.Boolean)]
+ [(poly.like Nat) (:: (~! ..Codec) (~' encode))]
+ [(poly.like Int) (:: (~! ..Codec) (~' encode))]
+ [(poly.like Frac) (|>> #//.Number)]
+ [(poly.like Text) (|>> #//.String)])