Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.5.0 #239

Merged
merged 110 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
9292c9b
bump version for dev-minor
dorchard Jul 25, 2023
1aa0d43
better localisation of type error for let<>
dorchard Jul 25, 2023
f0dc679
slight reorder in primitives for documentation purposes (moving fork …
dorchard Jul 25, 2023
0a0a6e9
improve docs; break long lines and show hidden names information
dorchard Jul 25, 2023
9f09250
improve docs formatting and pretty printing
dorchard Jul 25, 2023
7b28782
remove forkLinear' which was used for experimentation
dorchard Jul 25, 2023
33326bd
fix typo
dorchard Jul 25, 2023
a160a82
pushable alias for hsup constraints; fixes #182
dorchard Jul 26, 2023
77e9e34
make grepl types a bit more clear if there are poly vars around
dorchard Jul 26, 2023
519b5be
fix where hsup is used (should be in body)
dorchard Jul 26, 2023
dd146f4
put Set in scope
dorchard Jul 26, 2023
851d377
add hsup constraints to push; Pushable
dorchard Jul 26, 2023
0a0ec83
tests
dorchard Jul 26, 2023
758d593
update tests
dorchard Jul 26, 2023
421aeb5
handle ty constraints in grepl as well (helps to deal with the exampl…
dorchard Jul 26, 2023
6569e0e
fix constraint in List module
dorchard Jul 26, 2023
5653807
clear type checker state before synthing expression type in grepl - o…
dorchard Jul 26, 2023
fc393d4
store derived definitions generated from checking rest of file in rep…
dorchard Jul 26, 2023
e54d6be
remove duplicate deriving implementations due to modules
dorchard Jul 26, 2023
3582324
Merge pull request #220 from granule-project/derivingImprovements
dorchard Jul 26, 2023
790f95b
internalise existential binders into predicate
dorchard Jul 26, 2023
821f167
Revert "internalise existential binders into predicate"
dorchard Jul 26, 2023
43d0a89
fix bug associated with handled exception effects
dorchard Jul 26, 2023
555e55a
add a unicode synonym for the existential quantifier
starsandspirals Jul 27, 2023
2d4295e
tweak one example to use unicode exists
starsandspirals Jul 27, 2023
1a21959
add exists to ascii/unicode table in README
starsandspirals Jul 27, 2023
e2ce47c
add missing throw operation to evaluator
dorchard Jul 27, 2023
fd583db
fix formatting bug when splitting lines which don't have forall
dorchard Aug 7, 2023
7d9fbac
fix flattening for Sec when not in SecurityLevels mode
dorchard Aug 10, 2023
9e9ba91
add golden output for negative flatten sec test
dorchard Aug 10, 2023
e463814
dual is involution test reinstanted
dorchard Aug 10, 2023
5c1b6ca
Merge pull request #224 from granule-project/fixFlattenSec
jackohughes Aug 15, 2023
afc45c4
improve kinding with dependent kinds
dorchard Sep 19, 2023
8a3e258
generic effect operator
dorchard Sep 19, 2023
3e1c65d
terms for forall types and corresponding expressions
dorchard Sep 22, 2023
ac482d7
key positive test
dorchard Sep 22, 2023
6b6c936
synth kinds for forall types
dorchard Sep 22, 2023
361f35c
checking for tyapp and absty
dorchard Sep 22, 2023
c695077
equality on forall types and fixing up type checking
dorchard Sep 22, 2023
d6432cf
update test
dorchard Sep 22, 2023
2bca5c0
evaluator for higher rank quantification
dorchard Sep 22, 2023
1a26e71
fix name clash check so that it includes primitives
dorchard Sep 22, 2023
52da14b
extended test with free monad and higher order functions
dorchard Sep 23, 2023
c249a0d
fix freshening bug with new forall rankN
dorchard Sep 23, 2023
41ebeec
syntactic sugar for type signatures
dorchard Sep 23, 2023
63f5865
merge conflix resolution
dorchard Sep 23, 2023
ae62bc0
fix freshening bug with exists, and provide an example combining exis…
dorchard Sep 23, 2023
b7837c5
leverage rankN in generic effect op
dorchard Sep 23, 2023
9d86155
wip
dorchard Sep 23, 2023
baf1307
some commenting and commenting out
dorchard Sep 25, 2023
53cca3b
implicit->explicit resolver for rankN
dorchard Sep 25, 2023
99adb90
free graded monad eval and handle update
dorchard Sep 25, 2023
a1cf09f
embed free monad bind into handler implementation
dorchard Sep 25, 2023
5996742
tidyup examples
dorchard Sep 25, 2023
01515d1
add tests
dorchard Sep 25, 2023
2bf3df2
output for example
dorchard Sep 25, 2023
5eeef3c
documentation and version number bump
dorchard Sep 25, 2023
7c51b6e
documentation
dorchard Sep 25, 2023
c4f7ab6
non-determinism example
dorchard Sep 25, 2023
9aa2db0
increase power of solver in case we have resolved all cases of Nat \/…
dorchard Sep 25, 2023
6eca25d
typos thanks to @takanuva
dorchard Sep 25, 2023
a5a72ea
Merge, fix typos
dorchard Sep 25, 2023
bd702fb
Merge pull request #226 from granule-project/rankN
dorchard Sep 25, 2023
41f6bf8
cleanup
dorchard Sep 25, 2023
6b976b9
more cleeanup
dorchard Sep 25, 2023
4cd8318
cleanup
dorchard Sep 25, 2023
b931e76
graded handle rule
dorchard Sep 26, 2023
57f4079
make index checking for pi-type conversion more powerful (+ test)
dorchard Sep 26, 2023
452138c
Merge branch 'dev-minor' into effectHandlers
dorchard Sep 26, 2023
8245b4e
improve solving for sets by checking that the things in the set are i…
dorchard Sep 26, 2023
9aeff0e
fix error message reporting the wrong variable being unbound in data …
dorchard Sep 26, 2023
8e11c6b
some noodling around how sets are handled to improve solver
dorchard Sep 26, 2023
d750824
comments
dorchard Sep 26, 2023
7289f98
generalise 'call' so that it can reused by handle and gradedHandle, a…
dorchard Sep 27, 2023
d42f05d
fmap in handle needs to be nonlinear
dorchard Sep 28, 2023
3b29bbc
fix to kinding for Set (there was a bug)
dorchard Sep 28, 2023
2c6e206
generalise call/handle operations to work with arbitrary grading monoids
dorchard Sep 28, 2023
56e82a4
reused handle for handleGr
dorchard Sep 28, 2023
a94a1c0
fix a test
dorchard Sep 28, 2023
25b4e38
add concat operation for vectors
dorchard Sep 28, 2023
30c16ab
generalising the free graded monad
dorchard Sep 28, 2023
f11954e
fixes to implicit binders in pattern match
dorchard Sep 28, 2023
fa2a1d2
Merge pull request #227 from granule-project/effectHandlers
dorchard Sep 28, 2023
2a2b611
make sure primitives use the correct Maybe interface (see #190)
dorchard Oct 26, 2023
0b7bc1c
fixes #190
dorchard Oct 26, 2023
c4a0ba4
commented out tracing routine, could be useful in the future, but we …
dorchard Oct 26, 2023
212bcb2
Merge pull request #228 from granule-project/fix90
dorchard Nov 8, 2023
ac1564e
unification problem example
dorchard Jan 6, 2024
a83fada
Add flag --no-print-return-value
buggymcbugfix Jan 19, 2024
568a746
Merge pull request #231 from granule-project/buggymcbugfix/--no-print…
dorchard Jan 19, 2024
46f5001
fix drop so that it doesn't run forever with recursive types
dorchard Mar 7, 2024
82accfe
fixing copyShape; fixes #173
dorchard Mar 7, 2024
c6a5d7b
fixing copyShape; fixes #173
dorchard Mar 7, 2024
1347734
fix pretty printer so that it shows graded base types properly
dorchard Mar 7, 2024
6f948b4
update tests
dorchard Mar 7, 2024
38c1c18
add missing pattern arity check
dorchard Mar 7, 2024
2d180a5
slightly tweak algebraic effects interface
dorchard Mar 7, 2024
2517787
rename drop on vectors
dorchard Mar 7, 2024
65c87dc
make drop and copyShape have primitive placeholders for documentation…
dorchard Mar 7, 2024
e329e6c
fix typing for drop and report errors if ill-kinded uses
dorchard Mar 7, 2024
bb5202d
kind errors for deriving drop
dorchard Mar 7, 2024
9d89933
handle redefinition problems in evaluator around deriving
dorchard Mar 7, 2024
e3b8898
slight naming tweak
dorchard Mar 7, 2024
f804cec
ignore Premature end of file errors in LSP
dorchard Mar 8, 2024
77f9d9d
fix cost example to be more precise
dorchard Mar 8, 2024
5f07f3d
update some tests
dorchard Mar 8, 2024
24e2e35
synth test updates
dorchard Mar 8, 2024
a407009
fix some more tests
dorchard Mar 8, 2024
ee6e11c
update tests
dorchard Mar 8, 2024
577b71a
changelog
dorchard Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ the most recent copy of the input file with `.bak` appended.
| ASCII | Unicode |
|:---:|:---:|
| `forall` | `∀` |
| `exists` | `∃` |
| `Inf` | `∞` |
| `->` | `→` |
| `=>` | `⇒` |
Expand Down
16 changes: 14 additions & 2 deletions StdLib/List.gr
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,22 @@ foldr_list [f] z xs =

--- Push a graded modality inside a list (defined as `push @List`)
pushList : forall {s : Semiring, r : s, a : Type}
. {(1 : s) <= r} => (List a) [r] -> List (a [r])
. {(1 : s) <= r, Pushable r} => (List a) [r] -> List (a [r])
pushList = push @List

--- Pull a graded modality out of a list (defined as `pull @List`)
pullList : forall {s : Semiring, r : s, a : Type}
. List (a [r]) -> (List a) [r]
pullList = pull @List
pullList = pull @List

--- # List monad

return_list : forall {a : Type} . a -> List a
return_list x = Next x Empty

bind_list : forall {a b : Type} . (a -> List b) [] -> List a -> List b
bind_list [f] Empty = Empty;
bind_list [f] (Next x xs) = append_list (f x) (bind_list [f] xs)

join_list : forall {a : Type} . List (List a) -> List a
join_list = bind_list [\x -> x]
4 changes: 2 additions & 2 deletions StdLib/Prelude.gr
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ extract [x] = x
--- defined: the operation {c ⨱ c} is partial and is only defined if the semiring
--- `k` permits this behaviour at `c`. (An example of a semiring where this is not true
--- is for `k = LNL` and `c = 1`).
pushPair : forall {a : Type, b : Type, k : Coeffect, c : k} . {c ⨱ c} => (a × b) [c] -> a [c] × b [c]
pushPair [(x, y)] = ([x], [y])
pushPair : forall {a : Type, b : Type, k : Coeffect, c : k} . {Pushable c} => (a × b) [c] -> a [c] × b [c]
pushPair = push @(,)

--- Pull coeffects of pair elements outside of the pair
pullPair : ∀ {a : Type, b : Type, k : Coeffect, n : k} . (a [n], b [n]) → (a, b) [n]
Expand Down
16 changes: 11 additions & 5 deletions StdLib/Vec.gr
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ append
append Nil ys = ys;
append (Cons x xs) ys = Cons x (append xs ys)

--- Concatenate a vector of vectors
concat : forall {a : Type, m n : Nat} .
Vec n (Vec m a) -> Vec (n * m) a
concat Nil = Nil;
concat (Cons xs xss) = append xs (concat xss)

--- Drop the first `m` elements
drop
dropElems
: forall {a : Type, m n : Nat}
. N m -> (Vec n a) [0..1] -> Vec (n - m) a
drop Z [xs] = xs;
drop (S n) [Nil] = drop n [Nil];
drop (S n) [Cons _ xs] = drop n [xs]
dropElems Z [xs] = xs;
dropElems (S n) [Nil] = dropElems n [Nil];
dropElems (S n) [Cons _ xs] = dropElems n [xs]

--- Take the first `m` elements
take
Expand Down Expand Up @@ -170,7 +176,7 @@ pullVec : forall {a : Type, s : Semiring, k : s, n : Nat}
pullVec = pull @Vec

--- pushVec pushes in non linearity of vector into the elements
pushVec : ∀ {a : Type, s : Semiring, k : s, n : Nat} . {(1 : s) <= k}
pushVec : ∀ {a : Type, s : Semiring, k : s, n : Nat} . {(1 : s) <= k, Pushable k}
=> (Vec n a) [k] → Vec n (a [k])
pushVec = push @Vec

Expand Down
15 changes: 15 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# 0.9.5.0
- Rank N typing (see https://github.com/granule-project/granule/blob/dev-minor/examples/rankN.gr)
- Algebraic effects and handlers. See e.g.,
* https://github.com/granule-project/granule/blob/dev-minor/examples/effects_nondet.gr
* https://github.com/granule-project/granule/blob/dev-minor/examples/effects_state.gr
- Updated standard docs
- Fixes to deriving copyShape and drop combinators
- push deriving combinators now have Pushable constraint, e.g.

pushList : forall {s : Semiring, r : s, a : Type}
. {(1 : s) <= r, Pushable r} => (List a) [r] -> List (a [r])
pushList = push @List

- Minor tweaks to the Granule Language Server to improve vscode interaction (no longer complains on the entire file about 'Premature end of file' whilst typing).

# 0.9.4.0
- Advanced synthesis algorithm for `language GradeBase` mode.
- Better standard library documentation
Expand Down
9 changes: 4 additions & 5 deletions compiler/app/Language/Granule/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Language.Granule.Checker.Checker
import Language.Granule.Syntax.Def (extendASTWith)
import Language.Granule.Syntax.Preprocessor
import Language.Granule.Syntax.Parser
import Language.Granule.Syntax.Preprocessor.Ascii
import Language.Granule.Syntax.Pretty
import Language.Granule.Utils
import Paths_granule_compiler (version)
Expand Down Expand Up @@ -112,14 +111,14 @@ parseGrFlags
<=< getParseResult . execParserPure (prefs disambiguate) parseGrConfig . words

data GrConfig = GrConfig
{ grRewriter :: Maybe (String -> String)
{ grRewriter :: Maybe Rewriter
, grKeepBackup :: Maybe Bool
, grLiterateEnvName :: Maybe String
, grShowVersion :: Bool
, grGlobals :: Globals
}

rewriter :: GrConfig -> Maybe (String -> String)
rewriter :: GrConfig -> Maybe Rewriter
rewriter c = grRewriter c <|> Nothing

keepBackup :: GrConfig -> Bool
Expand Down Expand Up @@ -334,10 +333,10 @@ parseGrConfig = info (go <**> helper) $ briefDesc

grRewriter
<- flag'
(Just asciiToUnicode)
(Just AsciiToUnicode)
(long "ascii-to-unicode" <> help "WARNING: Destructively overwrite ascii characters to multi-byte unicode.")
<|> flag Nothing
(Just unicodeToAscii)
(Just UnicodeToAscii)
(long "unicode-to-ascii" <> help "WARNING: Destructively overwrite multi-byte unicode to ascii.")

grKeepBackup <-
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/Language/Granule/Compiler/HSCodegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ cgTypeScheme :: Compiler m => TypeScheme -> m (Hs.Type ())
cgTypeScheme (Forall _ binders constraints typ) = do
typ' <- cgType typ
let tyVars = map (UnkindedVar () . mkName . fst) binders
return $ TyForall () (Just tyVars) Nothing typ'
return $ Hs.TyForall () (Just tyVars) Nothing typ'

cgPats :: Compiler m => [CPat] -> m [Pat ()]
cgPats = mapM cgPat
Expand All @@ -104,7 +104,7 @@ cgPat (GrPat.PInt _ _ _ n) =
return $ PLit () (Signless ()) $ Int () (fromIntegral n) (show n)
cgPat (GrPat.PFloat _ _ _ n) =
return $ PLit () (Signless ()) $ Frac () (toRational n) (show n)
cgPat (GrPat.PConstr _ _ _ i l_pt)
cgPat (GrPat.PConstr _ _ _ i _ l_pt)
| i == Id "," "," = do
pts <- mapM cgPat l_pt
return $ pTuple pts
Expand Down Expand Up @@ -142,6 +142,7 @@ cgType (GrType.TySet p l_t) = return mkUnit
cgType (GrType.TyCase t l_p_tt) = unsupported "cgType: tycase not implemented"
cgType (GrType.TySig t t2) = unsupported "cgType: tysig not implemented"
cgType (GrType.TyExists _ _ _) = unsupported "cgType: tyexists not implemented"
cgType (GrType.TyForall _ _ _) = unsupported "cgType: tyforall not implemented"

isTupleType :: GrType.Type -> Bool
isTupleType (GrType.TyApp (GrType.TyCon id) _) = id == Id "," ","
Expand Down Expand Up @@ -220,6 +221,7 @@ cgVal (Abs _ p _ ex) = do
return $ lamE [p'] ex'
cgVal Pack{} = error "Existentials unsupported in code gen"
cgVal Ext{} = unexpected "cgVal: unexpected Ext"
cgVal TyAbs{} = error "Rank-N quantifiaction unsupported in code gen"


cgBinop :: Compiler m => Operator -> Exp () -> Exp () -> m (Exp ())
Expand Down
12 changes: 12 additions & 0 deletions docs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ body {
border-bottom: solid 3px #ccc;
}

.code pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}

.inline {
font-family: monospace;
background: rgb(250, 250, 250);
Expand Down Expand Up @@ -96,4 +104,8 @@ a.toplink {
font-size: 10pt;
margin-right: 2em;
color: #c9c9c9;
}

strong {
color: rgb(194, 20, 200);
}
3 changes: 1 addition & 2 deletions examples/cost.gr
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ two =
-- Prove (map f) in O(|f|n)

mapLinear : forall {a b : Type, n : Nat, f : Nat}
. (a -> b <f>) [] -> Vec n a -> (Vec n b) <n*f>

. (a -> b <f>) [n] -> Vec n a -> (Vec n b) <n*f>
mapLinear [_] Nil = pure Nil;
mapLinear [f] (Cons x xs) =
let y <- f x;
Expand Down
54 changes: 54 additions & 0 deletions examples/effects_nondet.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Example of using algebraic effects and handlers in Granule to capture
-- non-determinism effects

-- Uses the builtin `call` and `handle` operations.
-- See https://granule-project.github.io/docs/modules/Primitives.html#algebraiceffectsandhandlers

import List

-- # Coin toss game effect operations

data Labels = Toss | Drop

-- Operations
data GameOps : Set Labels -> Type -> Type where
FlipCoin : forall {r : Type} . () -> (Bool -> r) [2] -> GameOps {Toss} r;
Fumble : forall {r : Type} . () -> (Void -> r) [0] -> GameOps {Drop} r

-- -- Functoriality of operations
fmap_gameops : forall {a b : Type, l : Set Labels}
. (a -> b) [0..Inf] -> GameOps l a -> GameOps l b
fmap_gameops [f] (FlipCoin () [k]) = FlipCoin () [f . k];
fmap_gameops [f] (Fumble () [k]) = Fumble () [f . k]

-- -- Handler to list monad
handler : forall {a : Type, l : Set Labels} . GameOps l (List a) -> List a
handler (FlipCoin () [k]) = join_list (Next (k True) (Next (k False) Empty));
handler (Fumble () [k]) = Empty

-- # Examples

foo : Bool <Eff (Set Labels) GameOps {Toss}>
foo = call FlipCoin ()

-- Two coin flips, all good
example1 : (Bool, Bool) <Eff (Set Labels) GameOps {Toss}>
example1 = let
x <- call FlipCoin ();
y <- call FlipCoin ()
in pure (x, y)

-- -- Two coin flips, attempt, but fumble in the middle
example2 : (Bool, Bool) <Eff (Set Labels) GameOps {Toss,Drop}>
example2 = let
x <- call FlipCoin ();
a <- call Fumble ();
y <- call FlipCoin ()
in let () = drop @Void a in pure (x, y)

-- -- Easy runner
go : forall {e : Set Labels, a : Type} . a <Eff (Set Labels) GameOps e> -> List a
go = handle [/\{a,b,l}.fmap_gameops] [/\{l}.handler] (return_list)

main : List (Bool, Bool)
main = go example1
46 changes: 46 additions & 0 deletions examples/effects_state.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Example of using algebraic effects and handlers in Granule to capture
-- state effects

-- Uses the builtin `call` and `handle` operations.
-- See https://granule-project.github.io/docs/modules/Primitives.html#algebraiceffectsandhandlers

import State

-- # State operations

data Labels = Get | Put

-- Operations
data StateOps (s : Type) : (Set Labels) -> Type -> Type where
GetOp : forall {r : Type} . () -> (s -> r) [1] -> StateOps s {Get} r;
PutOp : forall {r : Type} . s [0..Inf] -> (() -> r) [1] -> StateOps s {Put} r

-- Functoriality of operations
fmap_stateops : forall {s a b : Type, l : Set Labels}
. (a -> b) [0..Inf] -> StateOps s l a -> StateOps s l b
fmap_stateops [f] (GetOp () [k]) = GetOp () [f . k];
fmap_stateops [f] (PutOp [s] [k]) = PutOp [s] [f . k]

-- Handler to state monad
stateHandler : forall {s r : Type, l : Set Labels}
. StateOps s l (State s r) -> State s r
stateHandler (GetOp () [k]) = join_state (State (\([s] : s [0..Inf]) -> (k s, [s])));
stateHandler (PutOp s [k]) = join_state (State (\([_] : s [0..Inf]) -> (k (), s)))

-- # Examples

incr : Int <Eff (Set Labels) (StateOps Int) {Get, Put}>
incr = let
y <- call GetOp ();
[z] <- pure (moveInt y);
() <- call PutOp [z + 1] in
pure z

-- Handle state wrapped
handleState : forall {a b : Type, e : Set Labels, s : Type}
. a <Eff (Set Labels) (StateOps s) e>
-> State s a
handleState = handle [/\{a,b,l}.fmap_stateops] [/\{l}.stateHandler] (return_state)

main : (Int, Int [])
main = runState (handleState incr) [42]
8 changes: 4 additions & 4 deletions examples/listToVec.gr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Vec
import List

listToVec : ∀ {a : Type} . List a → exists {n : Nat} . Vec n a
listToVec Empty = pack < 0 , Nil > as exists {n : Nat} . Vec n a;
listToVec : ∀ {a : Type} . List a → {n : Nat} . Vec n a
listToVec Empty = pack < 0 , Nil > as {n : Nat} . Vec n a;
listToVec (Next x xs) =
unpack < m , v > = listToVec xs
in pack < m + 1 , (Cons x v) > as exists {n : Nat} . Vec n a
in pack < m + 1 , (Cons x v) > as {n : Nat} . Vec n a

vecToList : ∀ {a : Type, n : Nat} . Vec n a → List a
vecToList Nil = Empty;
vecToList (Cons x xs) = Next x (vecToList xs)

iso : forall {a : Type} . List a -> List a
iso : {a : Type} . List a -> List a
iso x = unpack < n , list > = listToVec x in vecToList list
8 changes: 8 additions & 0 deletions examples/pad_left.gr
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import Vec

monus
: forall {m n : Nat}
. N m -> N n -> N (m - n)
monus m Z = m;
monus Z (S n') = monus Z n';
monus (S m') (S n') = monus m' n'


pad_left
: ∀ {a : Type, m : Nat, n : Nat}
. a [n - m]
Expand Down
14 changes: 14 additions & 0 deletions examples/rankN.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- A function expecting a rank-1 polymorphic function which it reuses at
-- two different types (`Char` and `()`)
foo : (forall {b : Type} . b -> (Int, b)) [2] -> ((Int, Char), (Int, ()))
foo [k] = ((k @ Char) 'a', (k @ ()) ())

-- Application of `foo` with a reusable type abstraction function
main : ((Int, Char), (Int, ()))
main = foo [(/\(t : Type) -> \(x : t) -> (42, x))]

-- Mixing existentials and rankN forall
unpacker : forall {f : Type → Type, a : Type} .
(exists {a : Type} . f a) → (forall {t : Type} . f t → a) → a
unpacker e f =
unpack < b , e' > = e in (f @ b) e'
2 changes: 1 addition & 1 deletion frontend/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: granule-frontend
version: '0.9.4.0'
version: '0.9.5.0'
synopsis: The Granule abstract-syntax-tree, parser and type checker libraries
author: Dominic Orchard, Vilem-Benjamin Liepelt, Harley Eades III, Jack Hughes, Preston Keel, Daniel Marshall, Michael Vollmer
copyright: 2018-22 authors
Expand Down
Loading
Loading