Browse Source

fix bug with validity checking of type definitions

pull/18/head
nisstyre56 10 years ago
parent
commit
87a4176bdd
  1. 3
      example.jl
  2. 34
      prelude.jl
  3. 6
      representation.js

3
example.jl

@ -1,6 +1,9 @@
defop 2 Left (a ++ b) defop 2 Left (a ++ b)
(a - b) (a - b)
def foo# 3
deftype Foo (A -> B) deftype Foo (A -> B)
;; here is a comment ;; here is a comment

34
prelude.jl

@ -2,11 +2,9 @@
;; It is sort of special in that it doesn't care whether there are any associated definitions ;; It is sort of special in that it doesn't care whether there are any associated definitions
;; just that there are type definitions for that particular binding's name ;; just that there are type definitions for that particular binding's name
deftype String (List Char)
deftype (List a) ;; Type definitions
(Empty | deftype String (A300 Char)
(Cons a (List a)))
deftype Int Intrinsic deftype Int Intrinsic
@ -18,6 +16,22 @@ deftype Byte Intrinsic
deftype Void Intrinsic deftype Void Intrinsic
deftype IO Intrinsic
deftype (List a)
(Empty |
(Cons a (List a)))
deftype (Maybe a)
(Nothing |
(Just a))
deftype (Either a b)
((Left a) |
(Right b))
;; List functions
(: :: (a -> (List a) -> (List a))) (: :: (a -> (List a) -> (List a)))
(map :: ((a -> b) -> (List a) -> (List b))) (map :: ((a -> b) -> (List a) -> (List b)))
@ -28,4 +42,16 @@ deftype Void Intrinsic
(!! :: (Int -> (List a) -> a)) (!! :: (Int -> (List a) -> a))
(take :: (Int -> (List a) -> (Maybe (List a))))
(drop :: (Int -> (List a) -> (Maybe (List a))))
;; Optional functions
(maybe :: (b -> (a -> b) -> (Maybe a) -> b))
(either :: ((b -> c) -> (b -> c) -> (Either a b) -> c))
;; I/O functions
(print :: (String -> (IO Void))) (print :: (String -> (IO Void)))

6
representation.js

@ -278,7 +278,7 @@ function TypeDecl(expression, type) {
"Left-hand-side of type declaration must not be in the type language" "Left-hand-side of type declaration must not be in the type language"
); );
} }
if (!isTypeExprRec(type)) { if (isTypeExprRec(type).failed) {
throw errors.JInternalError( throw errors.JInternalError(
"Right-hand-side of type declaration must be a type expression" "Right-hand-side of type declaration must be a type expression"
); );
@ -295,7 +295,7 @@ function DefType(lhs, rhs) {
/* Both rhs and lhs are expected /* Both rhs and lhs are expected
* to be fully desugared already * to be fully desugared already
*/ */
if (!isTypeExprRec(rhs) || if (isTypeExprRec(rhs).failed ||
!isTypeExpr(lhs)) { !isTypeExpr(lhs)) {
throw errors.JSyntaxError( throw errors.JSyntaxError(
rhs.linenum, rhs.linenum,
@ -331,7 +331,7 @@ function DataType(name, params, type) {
"which is a type operator"); "which is a type operator");
} }
_.each(params, checkName); _.each(params, checkName);
if (!isTypeExprRec(type)) { if (isTypeExprRec(type).failed) {
throw errors.JSyntaxError( throw errors.JSyntaxError(
type.linenum, type.linenum,
type.charnum, type.charnum,

Loading…
Cancel
Save