-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New syntax for function definitions (#2243)
- Closes #2060 - Closes #2189 - This pr adds support for the syntax described in #2189. It does not drop support for the old syntax. It is possible to automatically translate juvix files to the new syntax by using the formatter with the `--new-function-syntax` flag. E.g. ``` juvix format --in-place --new-function-syntax ``` # Syntax changes Type signatures follow this pattern: ``` f (a1 : Expr) .. (an : Expr) : Expr ``` where each `ai` is a non-empty list of symbols. Braces are used instead of parentheses when the argument is implicit. Then, we have these variants: 1. Simple body. After the signature we have `:= Expr;`. 2. Clauses. The function signature is followed by a non-empty sequence of clauses. Each clause has the form: ``` | atomPat .. atomPat := Expr ``` # Mutual recursion Now identifiers **do not need to be defined before they are used**, making it possible to define mutually recursive functions/types without any special syntax. There are some exceptions to this. We cannot forward reference a symbol `f` in some statement `s` if between `s` and the definition of `f` there is one of the following statements: 1. Local module 2. Import statement 3. Open statement I think it should be possible to drop the restriction for local modules and import statements
- Loading branch information
1 parent
0cc689a
commit 2c8a364
Showing
28 changed files
with
1,106 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule juvix-stdlib
updated
28 files
+3 −8 | Stdlib/Data/Bool.juvix | |
+18 −16 | Stdlib/Data/Bool/Base.juvix | |
+3 −6 | Stdlib/Data/Int.juvix | |
+45 −44 | Stdlib/Data/Int/Base.juvix | |
+26 −20 | Stdlib/Data/Int/Ord.juvix | |
+14 −11 | Stdlib/Data/Int/Range.juvix | |
+38 −39 | Stdlib/Data/List.juvix | |
+133 −128 | Stdlib/Data/List/Base.juvix | |
+26 −27 | Stdlib/Data/Maybe.juvix | |
+6 −6 | Stdlib/Data/Maybe/Base.juvix | |
+3 −6 | Stdlib/Data/Nat.juvix | |
+19 −17 | Stdlib/Data/Nat/Base.juvix | |
+4 −4 | Stdlib/Data/Nat/Gcd.juvix | |
+29 −23 | Stdlib/Data/Nat/Ord.juvix | |
+14 −11 | Stdlib/Data/Nat/Range.juvix | |
+24 −16 | Stdlib/Data/Product.juvix | |
+24 −24 | Stdlib/Data/Product/Base.juvix | |
+2 −4 | Stdlib/Data/String.juvix | |
+3 −4 | Stdlib/Data/String/Base.juvix | |
+3 −6 | Stdlib/Data/Unit.juvix | |
+27 −23 | Stdlib/Function.juvix | |
+2 −2 | Stdlib/System/IO/Bool.juvix | |
+2 −2 | Stdlib/System/IO/Int.juvix | |
+2 −2 | Stdlib/System/IO/Nat.juvix | |
+2 −2 | Stdlib/System/IO/String.juvix | |
+2 −2 | Stdlib/Trait/Eq.juvix | |
+11 −11 | Stdlib/Trait/Ord.juvix | |
+2 −2 | Stdlib/Trait/Show.juvix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,9 @@ | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
module Juvix.Compiler.Concrete.Data.NameRef where | ||
|
||
import Data.Kind qualified as GHC | ||
import Juvix.Compiler.Concrete.Data.Name qualified as C | ||
import Juvix.Compiler.Concrete.Data.ScopedName qualified as S | ||
import Juvix.Prelude hiding (show) | ||
import Prelude (show) | ||
|
||
type RefNameType :: S.IsConcrete -> GHC.Type | ||
type family RefNameType c = res | res -> c where | ||
RefNameType 'S.Concrete = S.Name | ||
RefNameType 'S.NotConcrete = S.Name' () | ||
|
||
type AxiomRef = AxiomRef' 'S.Concrete | ||
|
||
newtype AxiomRef' (n :: S.IsConcrete) = AxiomRef' | ||
{_axiomRefName :: RefNameType n} | ||
|
||
makeLenses ''AxiomRef' | ||
|
||
instance HasLoc AxiomRef where | ||
getLoc = getLoc . (^. axiomRefName) | ||
|
||
instance Hashable (RefNameType s) => Hashable (AxiomRef' s) where | ||
hashWithSalt i = hashWithSalt i . (^. axiomRefName) | ||
|
||
instance (Eq (RefNameType s)) => Eq (AxiomRef' s) where | ||
(==) = (==) `on` (^. axiomRefName) | ||
|
||
instance (Ord (RefNameType s)) => Ord (AxiomRef' s) where | ||
compare = compare `on` (^. axiomRefName) | ||
|
||
instance (Show (RefNameType s)) => Show (AxiomRef' s) where | ||
show = show . (^. axiomRefName) | ||
|
||
type InductiveRef = InductiveRef' 'S.Concrete | ||
|
||
newtype InductiveRef' (n :: S.IsConcrete) = InductiveRef' | ||
{ _inductiveRefName :: RefNameType n | ||
} | ||
|
||
makeLenses ''InductiveRef' | ||
|
||
instance HasLoc InductiveRef where | ||
getLoc = getLoc . (^. inductiveRefName) | ||
|
||
instance Hashable (RefNameType s) => Hashable (InductiveRef' s) where | ||
hashWithSalt i = hashWithSalt i . (^. inductiveRefName) | ||
|
||
instance (Eq (RefNameType s)) => Eq (InductiveRef' s) where | ||
(==) = (==) `on` (^. inductiveRefName) | ||
|
||
instance (Ord (RefNameType s)) => Ord (InductiveRef' s) where | ||
compare = compare `on` (^. inductiveRefName) | ||
|
||
instance (Show (RefNameType s)) => Show (InductiveRef' s) where | ||
show = show . (^. inductiveRefName) | ||
|
||
type FunctionRef = FunctionRef' 'S.Concrete | ||
|
||
newtype FunctionRef' (n :: S.IsConcrete) = FunctionRef' | ||
{ _functionRefName :: RefNameType n | ||
} | ||
|
||
makeLenses ''FunctionRef' | ||
|
||
instance HasLoc FunctionRef where | ||
getLoc = getLoc . (^. functionRefName) | ||
|
||
instance Hashable (RefNameType s) => Hashable (FunctionRef' s) where | ||
hashWithSalt i = hashWithSalt i . (^. functionRefName) | ||
|
||
instance (Eq (RefNameType s)) => Eq (FunctionRef' s) where | ||
(==) = (==) `on` (^. functionRefName) | ||
|
||
instance (Ord (RefNameType s)) => Ord (FunctionRef' s) where | ||
compare = compare `on` (^. functionRefName) | ||
|
||
instance (Show (RefNameType s)) => Show (FunctionRef' s) where | ||
show = show . (^. functionRefName) | ||
|
||
type ConstructorRef = ConstructorRef' 'S.Concrete | ||
|
||
newtype ConstructorRef' (n :: S.IsConcrete) = ConstructorRef' | ||
{ _constructorRefName :: RefNameType n | ||
} | ||
|
||
makeLenses ''ConstructorRef' | ||
|
||
instance HasLoc ConstructorRef where | ||
getLoc = getLoc . (^. constructorRefName) | ||
|
||
instance Hashable (RefNameType s) => Hashable (ConstructorRef' s) where | ||
hashWithSalt i = hashWithSalt i . (^. constructorRefName) | ||
|
||
instance (Eq (RefNameType s)) => Eq (ConstructorRef' s) where | ||
(==) = (==) `on` (^. constructorRefName) | ||
|
||
instance (Ord (RefNameType s)) => Ord (ConstructorRef' s) where | ||
compare = compare `on` (^. constructorRefName) | ||
|
||
instance (Show (RefNameType s)) => Show (ConstructorRef' s) where | ||
show = show . (^. constructorRefName) | ||
|
||
concreteFunctionRef :: C.Name -> FunctionRef' 'S.NotConcrete -> FunctionRef | ||
concreteFunctionRef s = over functionRefName (set S.nameConcrete s) |
Oops, something went wrong.