pycoq
pycoq copied to clipboard
return objects should probably be dicts instead of nested 2-tuples
res = coq.add(some_command, opts)
print(dict(res))
{'Added': (6, {'fname': ('ToplevelInput', None), 'line_nb': 2, 'bol_pos': 1, 'line_nb_last': 2, 'bol_pos_last': 1, 'bp': 66, 'ep': 70}, ('NewTip', None)), 'Completed': None}
{'CoqExn': ({'loc': {'fname': ('ToplevelInput', None), 'line_nb': 2, 'bol_pos': 1, 'line_nb_last': 2, 'bol_pos_last': 1, 'bp': 9, 'ep': 28}, 'stm_ids': None, 'backtrace': False, 'exn': None, 'pp': ('Pp_glue', ([('Pp_glue', ([],)), ('Pp_glue', ([('Pp_string', ('in ',)), ('Pp_string', ('Stm.add',)), ('Pp_string', (':',))],)), ('Pp_print_break', (1, 0)), ('Pp_glue', ([('Pp_glue', ([('Pp_string', ('Stm.add called for a different state (',)), ('Pp_string', ('1',)), ('Pp_string', (') than the tip: ',))],)), ('Pp_string', ('6',)), ('Pp_string', ('.',))],)), ('Pp_force_newline', None), ('Pp_string', ('This is not supported yet, sorry.',))],)), 'str': 'in Stm.add:\nStm.add called for a different state (1) than the tip: 6.\nThis is not supported yet, sorry.'},), 'Completed': None}
there's a mix of tuples, lists, and dicts in here. It should be like a json object: just dicts and lists.
python casts lists of 2-tuples to dicts really well. It's just a matter of threading it through the entire object.
Indeed, this is an artifact of of the way ppx_python works, for OCaml objects of the from Cons of t1 * t2 there is little choice but to return a tuple.
I agree that some cases can be improved, see also #4
For now we should indeed consider the interface low-level, and expose to users a better, typed-API