mirror of
https://github.com/anoma/juvix.git
synced 2024-11-30 14:13:27 +03:00
b8cd84170b
This PR updates the juvix-stdlib to the current main commit which includes: * https://github.com/anoma/juvix-stdlib/issues/59 * https://github.com/anoma/juvix-stdlib/issues/101 All the Juvix test suite files and examples in this repo have been updated to be compatible with the new stdlib.
87 lines
1.3 KiB
Plaintext
87 lines
1.3 KiB
Plaintext
-- Coercions
|
|
module test063;
|
|
|
|
import Stdlib.Prelude open;
|
|
|
|
trait
|
|
type T1 A := mkT1 {pp : A -> A};
|
|
|
|
trait
|
|
type T2 A := mkT2 {pp : A -> A};
|
|
|
|
trait
|
|
type T3 A := mkT3 {pp : A -> A};
|
|
|
|
trait
|
|
type T4 A := mkT4 {pp : A -> A};
|
|
|
|
instance
|
|
instT1 {A} : T1 A :=
|
|
mkT1@{
|
|
pp := id
|
|
};
|
|
|
|
coercion instance
|
|
fromT1toT2 {A} {{M : T1 A}} : T2 A :=
|
|
mkT2@{
|
|
pp := T1.pp {{M}}
|
|
};
|
|
|
|
coercion instance
|
|
fromT2toT3 {A} {{M : T2 A}} : T3 A :=
|
|
mkT3@{
|
|
pp := T2.pp {{M}}
|
|
};
|
|
|
|
coercion instance
|
|
fromT2toT4 {A} {{M : T2 A}} : T4 A :=
|
|
mkT4@{
|
|
pp := T2.pp {{M}}
|
|
};
|
|
|
|
instance
|
|
instT4 : T4 String :=
|
|
mkT4@{
|
|
pp (s : String) : String := s ++str "!"
|
|
};
|
|
|
|
trait
|
|
type U A := mkU {pp : A -> A};
|
|
|
|
trait
|
|
type U1 A := mkU1 {pp : A -> A};
|
|
|
|
trait
|
|
type U2 A := mkU2 {pp : A -> A};
|
|
|
|
coercion instance
|
|
fromU1toU {A} {{U1 A}} : U A :=
|
|
mkU@{
|
|
pp := U1.pp
|
|
};
|
|
|
|
coercion instance
|
|
fromU2toU {A} {{U2 A}} : U A :=
|
|
mkU@{
|
|
pp := U2.pp
|
|
};
|
|
|
|
instance
|
|
instU2 : U2 String := mkU2 id;
|
|
|
|
f {A} {{U A}} : A -> A := U.pp;
|
|
|
|
g {A} {{U1 A}} : A -> A := f;
|
|
|
|
h {A} {{U2 A}} : A -> A := f;
|
|
|
|
main : IO :=
|
|
printStringLn (T1.pp "a")
|
|
>>> printStringLn (T2.pp "b")
|
|
>>> printStringLn (T3.pp "c")
|
|
>>> printStringLn (T4.pp "d")
|
|
>>> printStringLn (U.pp "e")
|
|
>>> printStringLn (f "f")
|
|
>>> printStringLn (g {{mkU1 id}} "g")
|
|
>>> printStringLn (h "h");
|