[m-users.] My experiences with inst declarations and making them more user-friendly
Mark Brown
mark at mercurylang.org
Fri Mar 15 01:51:03 AEDT 2019
On Thu, Mar 14, 2019 at 10:11 PM Dirk Ziegemeyer <dirk at ziegemeyer.de> wrote:
>
> Hi,
>
> from time to time I try to take advantage of Mercury’s insts to allow for more static error checking. Usually these tries end very fast because of these reasons:
> 1. The standard library predicates (e.g. list, map, foldl) don’t preserve subtype-insts. I have to write mode-polymorphic version of these predicates to go on. These mode-polymorphic predicate declarations are much longer and therefore harder to understand. (http://lists.mercurylang.org/archives/users/2015-March/007866.html)
> 2. User-defined predicate declarations become much longer, because I have to declare not only the type, but also subtype-insts.
> 3. With mode-polymorphic versions of predicates, the error messages might become very long and hard to read.
>
> I’m wondering if it might be possible to make insts more user-friendly.
>
> Maybe syntactic sugar for insts could make predicate declarations shorter. For example:
> Allow inst non_empty_list to be defined on type-level instead of inst-level. The compiler should notice that type non_empty_list is nothing else than type list which has an attached inst non_empty_list.
>
> Do you think this kind of syntactic sugar would be - at least theoretically - possible?
See section 8.3.3 of the reference manual for a related feature for
higher-order types.
Mark
More information about the users
mailing list