Created
January 31, 2016 19:38
-
-
Save FlyingJester/7cf2228fa03f8ef06273 to your computer and use it in GitHub Desktop.
An example of defining a mode for a type that only maintains partial uniqueness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- module inst_test. | |
:- interface. | |
% An example of defining a mode for a type that only maintains partial uniqueness. | |
% The type. | |
% In the inst, we will want to keep the string unique, but we won't worry about the int's uniqueness. | |
:- type test ---> test(int, string). | |
% Define the start and end states for the test_di mode. | |
:- inst test_in_di ---> test(ground, unique). | |
:- inst test_out_di ---> test(ground, clobbered). | |
% Define the start and end states for the test_uo mode. | |
:- inst test_in_uo ---> test(free, free). | |
:- inst test_out_uo ---> test(ground, unique). | |
% Define the test_di and test_uo modes. | |
:- mode test_di == test_in_di >> test_out_di. | |
:- mode test_uo == test_in_uo >> test_out_uo. | |
% A quick predicate that uses this mode. | |
:- pred str_test(test::test_di, test::test_uo) is det. | |
:- implementation. | |
:- import_module string. | |
% Int is not unique, but string.append makes unique strings. | |
str_test(test(Int, Str), test(Int, string.append(Str, "!"))). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment