summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDougal <d.maclaurin@gmail.com>2023-12-13 11:25:30 -0500
committerDougal <d.maclaurin@gmail.com>2023-12-13 11:25:30 -0500
commit0ae018e174b89d651d2228797e04f519766750aa (patch)
tree5ee7d0a7fd3ddadf97f4509edb8d912359e604fc
parent1cbdee72fb3eaecf84b34e2b4d8fc8271d6510aa (diff)
Change `data` to `enum`
Matches Rust. `Data` is already super overloaded and product ADTs, which are more common, are better done with `struct`.
-rw-r--r--examples/raytrace.dx10
-rw-r--r--lib/diagram.dx2
-rw-r--r--lib/fft.dx2
-rw-r--r--lib/linalg.dx8
-rw-r--r--lib/netpbm.dx2
-rw-r--r--lib/parser.dx2
-rw-r--r--lib/plot.dx2
-rw-r--r--lib/prelude.dx18
-rw-r--r--lib/set.dx2
-rw-r--r--misc/dex.el2
-rw-r--r--src/lib/Lexing.hs2
-rw-r--r--src/lib/Types/Core.hs2
-rw-r--r--src/lib/Types/Source.hs2
13 files changed, 28 insertions, 28 deletions
diff --git a/examples/raytrace.dx b/examples/raytrace.dx
index 4e9ca85d..f51b6764 100644
--- a/examples/raytrace.dx
+++ b/examples/raytrace.dx
@@ -41,7 +41,7 @@ def cross(a:Vec 3, b:Vec 3) -> Vec 3 =
[a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 * b2 - a2 * b1]
# TODO: Use `data Color = Red | Green | Blue` and ADTs for index sets
-data Image =
+enum Image =
MkImage(height:Nat, width:Nat, Fin height => Fin width => Color)
xHat : Vec 3 = [1., 0., 0.]
@@ -92,12 +92,12 @@ BlockHalfWidths = Vec 3
Radius = Float
Radiance = Color
-data ObjectGeom =
+enum ObjectGeom =
Wall(Direction, Distance)
Block(Position, BlockHalfWidths, Angle)
Sphere(Position, Radius)
-data Surface =
+enum Surface =
Matte(Color)
Mirror
@@ -105,7 +105,7 @@ struct OrientedSurface =
normal : Direction
surface : Surface
-data Object =
+enum Object =
PassiveObject(ObjectGeom, Surface)
# position, half-width, intensity (assumed to point down)
Light(Position, Float, Radiance)
@@ -169,7 +169,7 @@ def sdScene(scene:Scene n, pos:Position) -> (Object, Distance) given (n|Ix) =
def calcNormal(obj:Object, pos:Position) -> Direction =
grad(\p:Position. sdObject(p, obj)) pos | normalize
-data RayMarchResult =
+enum RayMarchResult =
# incident ray, surface normal, surface properties
HitObj(Ray, OrientedSurface)
HitLight(Radiance)
diff --git a/lib/diagram.dx b/lib/diagram.dx
index 7b5c52b7..2868c634 100644
--- a/lib/diagram.dx
+++ b/lib/diagram.dx
@@ -6,7 +6,7 @@ struct Point =
x : Float
y : Float
-data Geom =
+enum Geom =
PointGeom
Circle(Float)
Rectangle(Float, Float) # width, height
diff --git a/lib/fft.dx b/lib/fft.dx
index 87b28c0f..825a2c6f 100644
--- a/lib/fft.dx
+++ b/lib/fft.dx
@@ -22,7 +22,7 @@ def odd_sized_palindrome(mid:a, seq:n=>a) -> ((n `Either` () `Either` n)=>a) giv
'## Inner FFT functions
-data FTDirection =
+enum FTDirection =
ForwardFT
InverseFT
diff --git a/lib/linalg.dx b/lib/linalg.dx
index 037f692a..925099a6 100644
--- a/lib/linalg.dx
+++ b/lib/linalg.dx
@@ -23,10 +23,10 @@ def lower_tri_identity() -> LowerTriMat n a given(n|Ix, a|Add|Mul) =
'## Representing inequalities between indices
# These would be unnecessary if there were syntax for dependent pairs.
-data LowerTriIx(n) = MkLowerTriIx( i:n, j:(..i))
-data UpperTriIx(n) = MkUpperTriIx( i:n, j:(i..))
-data LowerTriIxExc(n) = MkLowerTriIxExc(i:n, j:(..<i))
-data UpperTriIxExc(n) = MkUpperTriIxExc(i:n, j:(i<..))
+enum LowerTriIx(n) = MkLowerTriIx( i:n, j:(..i))
+enum UpperTriIx(n) = MkUpperTriIx( i:n, j:(i..))
+enum LowerTriIxExc(n) = MkLowerTriIxExc(i:n, j:(..<i))
+enum UpperTriIxExc(n) = MkUpperTriIxExc(i:n, j:(i<..))
'## Flipping inequalities between indices
diff --git a/lib/netpbm.dx b/lib/netpbm.dx
index a5cd6043..deada0ca 100644
--- a/lib/netpbm.dx
+++ b/lib/netpbm.dx
@@ -4,7 +4,7 @@
import parser
-data Image =
+enum Image =
MkImage(rows:Nat, cols:Nat, pixels:(Fin rows => Fin cols => Fin 3 => Word8))
parse_p6 : Parser Image = MkParser \h.
diff --git a/lib/parser.dx b/lib/parser.dx
index 12b82bdc..1ca78095 100644
--- a/lib/parser.dx
+++ b/lib/parser.dx
@@ -25,7 +25,7 @@ struct ParserHandle(h:Heap) =
input: String
offset: Ref h Nat
-data Parser(a:Type) =
+enum Parser(a:Type) =
MkParser((given(h:Heap), ParserHandle h )-> {Except, State h} a)
def parse(handle:ParserHandle h, parser:Parser a) -> {Except, State h} a given (a, h) =
diff --git a/lib/plot.dx b/lib/plot.dx
index f7c00885..2859ddb8 100644
--- a/lib/plot.dx
+++ b/lib/plot.dx
@@ -3,7 +3,7 @@
import diagram
import png
-data CompactSet(a:Type) =
+enum CompactSet(a:Type) =
Interval(a, a)
Singleton(a)
diff --git a/lib/prelude.dx b/lib/prelude.dx
index 8c62e15b..fde3cf19 100644
--- a/lib/prelude.dx
+++ b/lib/prelude.dx
@@ -491,7 +491,7 @@ instance VSpace(())
'## Boolean type
-data Bool =
+enum Bool =
False
True
@@ -530,7 +530,7 @@ def b_to_f(x:Bool) -> Float = i_to_f(b_to_i x)
'## Ordering
TODO: move this down to with `Ord`?
-data Ordering =
+enum Ordering =
LT
EQ
GT
@@ -542,7 +542,7 @@ A [sum type, or tagged union](https://en.wikipedia.org/wiki/Tagged_union) can ho
For those familiar with the C language, they can be though of as a combination of an `enum` with a `union`.
Here we define several basic kinds, and some operators on them.
-data Maybe(a:Type) =
+enum Maybe(a:Type) =
Nothing
Just(a)
@@ -558,7 +558,7 @@ def maybe(d:b, f:(a)->b, x:Maybe a) -> b given (a:Type, b:Type) =
Nothing -> d
Just(x') -> f x'
-data Either(a:Type, b:Type) =
+enum Either(a:Type, b:Type) =
Left(a)
Right(b)
@@ -630,7 +630,7 @@ def (:=)(ref:Ref h s, x:s) -> {State h} () given (h:Heap, s|Data) = %put(ref, x)
def ask(ref:Ref h r) -> {Read h} r given (h:Heap, r|Data) = %ask(ref)
-data AccumMonoidData(h:Heap, w:Type) = UnsafeMkAccumMonoidData(b:Type, Monoid b)
+enum AccumMonoidData(h:Heap, w:Type) = UnsafeMkAccumMonoidData(b:Type, Monoid b)
interface AccumMonoid(h:Heap, w:Type)
getAccumMonoidData : AccumMonoidData(h, w)
@@ -1329,7 +1329,7 @@ def deriv_rev(f:(Float)->Float, x:Float) -> Float = (snd vjp(f, x))(1.0)
# XXX: Watch out when editing this data type! We depend on its structure
# deep inside the compiler (mostly in linearization and during rule registration).
-data SymbolicTangent(a:Type) =
+enum SymbolicTangent(a:Type) =
ZeroTangent
SomeTangent(a)
@@ -1398,7 +1398,7 @@ def check_deriv(f:(Float)->Float, x:Float) -> Bool =
'## Length-erased lists
-data List(a:Type) =
+enum List(a:Type) =
AsList(n:Nat, elements:(Fin n => a))
instance Eq(List a) given (a|Eq)
@@ -1588,7 +1588,7 @@ def from_nullable_raw_ptr(ptr:RawPtr) -> Maybe (Ptr a) given (a:Type) =
def c_string_ptr(s:CString) -> Maybe (Ptr Char) = from_nullable_raw_ptr s.ptr
-data StreamMode =
+enum StreamMode =
ReadMode
WriteMode
@@ -1629,7 +1629,7 @@ def while(body: () -> {|eff} Bool) -> {|eff} () given (eff:Effects) =
body' : () -> {|eff} Word8 = \. b_to_w8 $ body()
%while(body')
-data IterResult(a|Data) =
+enum IterResult(a|Data) =
Continue
Done(a)
diff --git a/lib/set.dx b/lib/set.dx
index babe2ee4..c92c6229 100644
--- a/lib/set.dx
+++ b/lib/set.dx
@@ -44,7 +44,7 @@ def remove_duplicates_from_sorted(xs:n=>a) -> List a given (n|Ix, a|Eq) =
'## Sets
-data Set(a|Ord) =
+enum Set(a|Ord) =
# Guaranteed to be in sorted order with unique elements,
# as long as no one else uses this constructor.
# Instead use the "toSet" function below.
diff --git a/misc/dex.el b/misc/dex.el
index de892c45..69cf5f85 100644
--- a/misc/dex.el
+++ b/misc/dex.el
@@ -12,7 +12,7 @@
("^:\\w*" . font-lock-preprocessor-face)
(,(concat
"\\bdef\\b\\|\\bfor\\b\\|\\brof\\b\\|\\bcase\\b\\|"
- "\\bstruct\\b\\|\\bdata\\b\\|\\bwhere\\b\\|\\bof\\b\\|"
+ "\\bstruct\\b\\|\\benum\\b\\|\\bwhere\\b\\|\\bof\\b\\|"
"\\bif\\b\\|\\bthen\\b\\|\\belse\\b\\|\\binterface\\b\\|"
"\\binstance\\b\\|\\bgiven\\b\\|\\bdo\\b\\|\\bview\\b\\|"
"\\bwith\\b\\|\\bself\\b\\|"
diff --git a/src/lib/Lexing.hs b/src/lib/Lexing.hs
index ec916f74..71ff733d 100644
--- a/src/lib/Lexing.hs
+++ b/src/lib/Lexing.hs
@@ -107,7 +107,7 @@ keyWordToken = \case
ThenKW -> "then"
ElseKW -> "else"
OfKW -> "of"
- DataKW -> "data"
+ DataKW -> "enum"
StructKW -> "struct"
InterfaceKW -> "interface"
InstanceKW -> "instance"
diff --git a/src/lib/Types/Core.hs b/src/lib/Types/Core.hs
index daee7511..8e4a43cc 100644
--- a/src/lib/Types/Core.hs
+++ b/src/lib/Types/Core.hs
@@ -2079,7 +2079,7 @@ instance Pretty (TyConParams n) where
pretty (TyConParams _ _) = undefined
instance Pretty (TyConDef n) where
- pretty (TyConDef name _ bs cons) = "data" <+> pretty name <+> pretty bs <> pretty cons
+ pretty (TyConDef name _ bs cons) = "enum" <+> pretty name <+> pretty bs <> pretty cons
instance Pretty (DataConDefs n) where
pretty = undefined
diff --git a/src/lib/Types/Source.hs b/src/lib/Types/Source.hs
index 26fdda5d..803b685b 100644
--- a/src/lib/Types/Source.hs
+++ b/src/lib/Types/Source.hs
@@ -1089,7 +1089,7 @@ instance Pretty (UAlt n) where
instance Pretty (UTopDecl n l) where
pretty = \case
UDataDefDecl (UDataDef nm bs dataCons) bTyCon bDataCons ->
- "data" <+> p bTyCon <+> p nm <+> spaced (unsafeFromNest bs) <+> "where" <> nest 2
+ "enum" <+> p bTyCon <+> p nm <+> spaced (unsafeFromNest bs) <+> "where" <> nest 2
(prettyLines (zip (toList $ unsafeFromNest bDataCons) dataCons))
UStructDecl bTyCon (UStructDef nm bs fields defs) ->
"struct" <+> p bTyCon <+> p nm <+> spaced (unsafeFromNest bs) <+> "where" <> nest 2