Skip to content

Instantly share code, notes, and snippets.

@li-boxuan
Last active March 21, 2018 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li-boxuan/8dd7a1a07b803e5d9b3b5d4fa998260f to your computer and use it in GitHub Desktop.
Save li-boxuan/8dd7a1a07b803e5d9b3b5d4fa998260f to your computer and use it in GitHub Desktop.
test sample for part one
Step 1.
Build a valid example and an invalid example separately. (why the latter one is invalid?)
> valid_example = unify (Function [TypeVar "s1", TypeVar "s2", TypeVar "s3"] (TypeVar "s3")) (Function [Bool_, TypeVar "s4", Int_] Int_)
> invalid_example = unify (Function [TypeVar "s1", TypeVar "s2", TypeVar "s3"] (TypeVar "s3")) (Function [Bool_, TypeVar "s4", Int_] Bool_)
Step 2.
Test the consolidate function
> valid_example >>= consolidate
Just (fromList [(TypeVar "s1",Bool_),(TypeVar "s2",TypeVar "s4"),(TypeVar "s3",Int_)])
> invalid_example >>= consolidate
Nothing
Step 3.
Test the resolve function
> resolve_helper (Just constraints) = resolve constraints
> resolve_helper (valid_example >>= consolidate) (TypeVar "s1")
Bool_
> resolve_helper (valid_example >>= consolidate) (TypeVar "s2")
TypeVar "s4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment