From 085817c69d145400eac84e09704f48ede2bece68 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 14 Aug 2024 18:08:54 +0300 Subject: compiling example of a res struct --- examples/res.ek | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/res.ek (limited to 'examples') diff --git a/examples/res.ek b/examples/res.ek new file mode 100644 index 0000000..f7c96df --- /dev/null +++ b/examples/res.ek @@ -0,0 +1,25 @@ +/* simple example with C-like strings. A real implementation would likely want + * to use a string wrapper or something. */ + +typedef i27 {} +typedef i9 {} + +typedef res[any T] { + *i9 e; + T v; + + ok(T v => res![T]) { + return res![T]{.e = 0 as *i9, .v = v}; + } + + error(*i9 e, T v => res![T]) { + return res![T]{.e = e, .v = v}; + } +} + +define any[] {} + +main() +{ + const a = ok::res![i27](20); +} -- cgit v1.3