Example #1
0
 def overload_print(var_type, fmt):
     with overload('print', var_type >> io(unit), 's'):
         fmt = codegen.string_lit(cs, fmt)
         printf_args = [ fmt, cs.load_var('s') ]
         cs.builder.call( printf, printf_args )
         cs.builder.ret_void()
Example #2
0
        fresh = ts.generalize(t).body

        variables = fresh.variables()
        assert len(variables) == 1

        c = typeclass.Var()
        c.context.add(tc)

        a = next(iter(variables))
        subst = {a: c}
        ts.declare(name, t.substitute(subst) )


with hm.Var() as a:
    print_class = typeclass.Typeclass('print', {
        'print': a >> io(unit)
    })


declare_typeclass( print_class )
    
# instances
for t in string, integer, real, boolean:
    print_class.add_instance( ts.generalize(t) )
    

# TODO automatize from definition

with hm.Var() as a:
    eq = typeclass.Typeclass('eq', {
        '=': a >> (a >> boolean)