Scryer-prolog: keysort/2 wrong type errors

Created on 3 May 2018  路  7Comments  路  Source: mthom/scryer-prolog

prolog> ?- keysort([a-1],[X|b]).
false.                                                         % expected: type_error(list,[_|b])
prolog> ?- keysort([a],L).
error: exception thrown: error(type_error(callable, a), _12)  % expected: type_error(pair,a)

All 7 comments

Further error:

prolog> ?- keysort([], L).
error: exception thrown: error(type_error(list, []), _10) % Expected: L = []

You really need some more systematic type testing. In general, you need

  • a test for the (fully) instantiated type which produces an instantiation error or a type error. This is used for input arguments

  • a test just for the type which is not associated with a instantiation error. This is typically used for output arguments.

It seem (I did not look into the code, though) that you have some more ad hoc testing implemented

I recommend to implement such checks with a Prolog predicate like must_be/2. It is easier to reason about types on the Prolog level.

Is must_be/2 documented somewhere that's not the SWI site?

SICStus Prolog provides a similar and more general version of this predicate in library(types), please see the documentation for more information:

https://sicstus.sics.se/sicstus/docs/latest4/html/sicstus.html/lib_002dtypes.html#lib_002dtypes

@mthom: Please note that must_be/2 is quite inconsistent. It's OK for must_be(list, Xs) but not for everything else.

@triska: These tests are needed on an internal level, too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

srenatus picture srenatus  路  4Comments

XVilka picture XVilka  路  3Comments

notoria picture notoria  路  3Comments

triska picture triska  路  3Comments

UWN picture UWN  路  3Comments