def visit_FunctionDef(self, node): monad_any_t = func_call(name(self.monad_name), []) # from contract import any_t, kleisli_arrow import_contract = ast.ImportFrom( module="monadic.monad_def", names=map_list(alias, ["kleisli_arrow", "unit"])) ast.fix_missing_locations(import_contract) # from monad_module import monad_name import_monad = ast.ImportFrom(module=self.module_name, names=map_list(alias, [self.monad_name])) ast.fix_missing_locations(import_monad) # bind = kleisli_arrow(monad_name(any_t)) bind = ast.Assign( [name_store('bind')], func_call(name('kleisli_arrow'), [monad_any_t]) ) ast.fix_missing_locations(bind) # unit = unit(monad_name(any_t)) unit = ast.Assign( [name_store('unit')], func_call(name('unit'), [monad_any_t]) ) ast.fix_missing_locations(unit) # non_monadic = unit normal = ast.Assign( [name_store('normal')], name('unit') ) ast.fix_missing_locations(normal) node.body = [import_contract, import_monad, bind, unit, normal] + node.body return node
def fmap(l): return map_list(c, l)