Install lean4 (using elan), and run:
lean --c=hello.c hello.lean
// Lean compiler output | |
// Module: hello | |
// Imports: Init | |
#include <lean/lean.h> | |
#if defined(__clang__) | |
#pragma clang diagnostic ignored "-Wunused-parameter" | |
#pragma clang diagnostic ignored "-Wunused-label" | |
#elif defined(__GNUC__) && !defined(__CLANG__) | |
#pragma GCC diagnostic ignored "-Wunused-parameter" | |
#pragma GCC diagnostic ignored "-Wunused-label" | |
#pragma GCC diagnostic ignored "-Wunused-but-set-variable" | |
#endif | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
lean_object* l_getOrOne(lean_object*); | |
lean_object* l_getOrOne_match__1(lean_object*); | |
lean_object* l_getOrOne___boxed(lean_object*); | |
lean_object* l_getOrOne_match__1___rarg(lean_object*, lean_object*, lean_object*); | |
lean_object* l_getOrOne_match__1___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3) { | |
_start: | |
{ | |
if (lean_obj_tag(x_1) == 0) | |
{ | |
lean_object* x_4; lean_object* x_5; | |
lean_dec(x_3); | |
x_4 = lean_box(0); | |
x_5 = lean_apply_1(x_2, x_4); | |
return x_5; | |
} | |
else | |
{ | |
lean_object* x_6; lean_object* x_7; | |
lean_dec(x_2); | |
x_6 = lean_ctor_get(x_1, 0); | |
lean_inc(x_6); | |
lean_dec(x_1); | |
x_7 = lean_apply_1(x_3, x_6); | |
return x_7; | |
} | |
} | |
} | |
lean_object* l_getOrOne_match__1(lean_object* x_1) { | |
_start: | |
{ | |
lean_object* x_2; | |
x_2 = lean_alloc_closure((void*)(l_getOrOne_match__1___rarg), 3, 0); | |
return x_2; | |
} | |
} | |
lean_object* l_getOrOne(lean_object* x_1) { | |
_start: | |
{ | |
if (lean_obj_tag(x_1) == 0) | |
{ | |
lean_object* x_2; | |
x_2 = lean_unsigned_to_nat(1u); | |
return x_2; | |
} | |
else | |
{ | |
lean_object* x_3; | |
x_3 = lean_ctor_get(x_1, 0); | |
lean_inc(x_3); | |
return x_3; | |
} | |
} | |
} | |
lean_object* l_getOrOne___boxed(lean_object* x_1) { | |
_start: | |
{ | |
lean_object* x_2; | |
x_2 = l_getOrOne(x_1); | |
lean_dec(x_1); | |
return x_2; | |
} | |
} | |
lean_object* initialize_Init(lean_object*); | |
static bool _G_initialized = false; | |
lean_object* initialize_hello(lean_object* w) { | |
lean_object * res; | |
if (_G_initialized) return lean_io_result_mk_ok(lean_box(0)); | |
_G_initialized = true; | |
res = initialize_Init(lean_io_mk_world()); | |
if (lean_io_result_is_error(res)) return res; | |
lean_dec_ref(res); | |
return lean_io_result_mk_ok(lean_box(0)); | |
} | |
#ifdef __cplusplus | |
} | |
#endif |
inductive MaybeNat where | |
| None | |
| Just (n: Nat) | |
open MaybeNat | |
def getOrOne (m:MaybeNat) : Nat := | |
match m with | |
| None => 1 | |
| Just n => n | |