Mercury Bugs - mercury
View Issue Details
0000323mercuryBugpublic2014-04-02 22:532014-04-03 01:21
Assigned To 
PlatformLinuxOSDebianOS Versionwheezy (7.0)
Product Version 
Target VersionFixed in Version 
Summary0000323: Matching on adts makes and instantiation state subtyping is impossible.
DescriptionMatching on a subtype doesn't carry the information about the inst of the subtype which makes using pattern matching and instantiation state subtyping impossible to use. See the attached file for details.
Steps To Reproduce$ mmc --version
Mercury Compiler, version 13.05.2, configured for x86_64-unknown-linux-gnu
Copyright (C) 1993-2013 The University of Melbourne

$ mmc -E subtyping.m
subtyping.m:019: In clause for `use_everything(in, out)':
subtyping.m:019: mode error in conjunction. The next 2 error messages
subtyping.m:019: indicate possible causes of this error.
subtyping.m:019: In clause for `use_everything(in, out)':
subtyping.m:019: in argument 1 of call to predicate `subtyping.use_bar'/2:
subtyping.m:019: mode error: variable `Bar' has instantiatedness `ground',
subtyping.m:019: expected instantiatedness was
subtyping.m:019: `bound('.
subtyping.m:019: In clause for `use_everything(in, out)':
subtyping.m:019: in argument 2 of clause head:
subtyping.m:019: mode error in unification of `HeadVar__2' and `String'.
subtyping.m:019: Variable `HeadVar__2' has instantiatedness `free',
subtyping.m:019: variable `String' has instantiatedness `free'.
TagsNo tags attached.
Attached Files? subtyping.m (491) 2014-04-02 22:53

2014-04-03 01:09   
You can work around the above problem by rewriting the predicate use_everything/2 to use a single clause, for example:

   use_everything(Foo, String) :-
           Foo = bar(_),
           use_bar(Foo, String)
           Foo = baz(_),
           String = "baz"
2014-04-03 01:17   
(Last edited: 2014-04-03 01:21)
Interesting, thank you very much! Paul Bone on #mercury irc also suggested deconstructing and reconstructing bar like:

use_everything(bar(X), String) :- use_bar(bar(X), String).

which works too. Still I think that, ideally, this should also work in pattern matching in multiple clauses(?).

Issue History
2014-04-02 22:53bwitkowskiNew Issue
2014-04-02 22:53bwitkowskiFile Added: subtyping.m
2014-04-03 01:09juliensfNote Added: 0000656
2014-04-03 01:17bwitkowskiNote Added: 0000657
2014-04-03 01:21bwitkowskiNote Edited: 0000657bug_revision_view_page.php?bugnote_id=657#r17