[m-dev.] diff: typeclasses

Fergus Henderson fjh at cs.mu.oz.au
Sat Nov 29 03:16:46 AEDT 1997


David Glen JEFFERY wrote:

> +	map__init(Proofs),
> +		% XXX
> +		% XXX This is wrong --- the context isn't nec. empty
> +		% XXX
>  	pred_info_init(ModuleName, PredName, Arity, TVarSet, Types, Cond,
> -		Context, ClausesInfo, local, [], none, PredOrFunc, PredInfo0),
> +		Context, ClausesInfo, local, [], none, PredOrFunc, [], Proofs,
> +		PredInfo0),
>  	pred_info_set_marker_list(PredInfo0, [request(infer_type)], PredInfo),
>  	(
>  		\+ predicate_table_search_pf_sym_arity(PredicateTable0,

Well, you should fix this XXX.
That should keep you busy for a little while.

>  c_gen_goal_2(higher_order_call(_, _, _, _, _, _), _, _, _) -->
> +	{ error("mercury_to_c: higher_order_call not implemented") }.
> +c_gen_goal_2(class_method_call(_, _, _, _, _, _), _, _, _) -->
>  	{ error("mercury_to_c: higher_order_call not implemented") }.

s/higher_order/class_method/

>  mercury_output_item(nothing, _) --> [].
> +mercury_output_item(typeclass(Constraints, ClassName, Vars, Methods, 
> +		VarSet), _) --> 
> +	io__write_string(":- typeclass "),
> +
> +		% We put an extra set of brackets around the class name in
> +		% case the name is an operator
> +	io__write_char('('),
> +	mercury_output_sym_name(ClassName),

I don't think the extra brackets are necessary.
Can you give an example where they are?

> +output_instance_methods(Methods) -->
> +	{ OutputMethod = lambda([Method::in, IO0::di, IO::uo] is det,
> +		(
> +			(
> +				Method = func_instance(Name1, Name2, Arity),
> +				io__write_string("func((", IO0, IO1)
> +			;
> +				Method = pred_instance(Name1, Name2, Arity),
> +				io__write_string("pred((", IO0, IO1)
> +			),
> +			mercury_output_bracketed_sym_name(Name1, IO1, IO2),
> +			io__write_string(")/", IO2, IO3),
> +			io__write_int(Arity, IO3, IO4),
> +			io__write_string(") is ", IO4, IO5),

Here too I don't think you need the extra parentheses, because
mercury_output_bracketed_sym_name will put the symbol in brackets
if it is an operator.

P.S. Do you have any test cases for the cases where typeclasses /
types used in instance declarations / method names are operators?
That would probably be a good idea.

> +mercury_output_func_type(VarSet, FuncName, Types, RetType, MaybeDet, 
> +		ClassContext, Context) -->
> +	mercury_output_func_type2(VarSet, FuncName, Types, RetType, MaybeDet, 
> +			ClassContext, Context, ".\n").
> +
> +:- pred mercury_output_func_type2(varset, sym_name, list(type), type,
> +		maybe(determinism), list(class_constraint),
> +		term__context, string, io__state, io__state).
> +:- mode mercury_output_func_type2(in, in, in, in, in, in, in, in, 
> +	di, uo) is det.
> +
> +mercury_output_func_type2(VarSet, FuncName, Types, RetType, MaybeDet, 
> +		ClassContext, _Context, Separator) -->

Please s/type2/type_2/g.

>  	% Output a mode declaration for a predicate.
>  
>  mercury_output_pred_mode_decl(VarSet, PredName, Modes, MaybeDet, Context) -->
> +	mercury_output_pred_mode_decl2(VarSet, PredName, Modes, MaybeDet,
> +		Context, ".\n").
> +
> +:- pred mercury_output_pred_mode_decl2(varset, sym_name, list(mode),
> +		maybe(determinism), term__context, string, 
> +		io__state, io__state).
> +:- mode mercury_output_pred_mode_decl2(in, in, in, in, in, in, di, uo) is det.
> +
> +mercury_output_pred_mode_decl2(VarSet, PredName, Modes, MaybeDet, Context,
> +		Separator) -->

Please s/decl2/decl_2/g

To be continued.
Let me know if you get close to running out of things to do ;-)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   WWW: <http://www.cs.mu.oz.au/~fjh>  
Note: due to some buggy software and a (probably accidental)
denial-of-service attack, any mail sent to me between
	Tue Nov 25 20:00:00 UTC (6am Wed, local time)
and	Wed Nov 26 06:00:00 UTC (4pm, local time)
may have gone into the bit-bucket.  Please re-send it.



More information about the developers mailing list