Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example #11

Closed
wants to merge 2 commits into from
Closed

example #11

wants to merge 2 commits into from

Conversation

chenyan-dfinity
Copy link
Contributor

No description provided.

public type Comparable<T> = {
compare : (T, T) -> Order;
};
public type t<T> = makeHeap<T>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand type names should be capitalized, but Heap.t<Int> also looks nice.

};
public type t<T> = makeHeap<T>;
public class makeHeap<T>(ord : Comparable<T>) {
type t<T> = ?(Int, T, t<T>, t<T>);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if I can say type t = ?(Int, T, t, t);, but it is not allowed.

@@ -50,9 +56,10 @@ module {
case (?(_, _, a, b)) heap := merge(a,b);
}
};
// Ideally this should be a static function. Also don't know how to return self
public func fromList(a : L.List<T>) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should be a static function. I can move this function out of the class, but I don't know how to return makeHeap<T> without breaking encapsulation.

compare : (T, T) -> Order;
};
public type t<T> = makeHeap<T>;
public class makeHeap<T>(ord : Comparable<T>) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class feels like a functor, so I use makeHeap instead of Heap. And to reference the type I defined a type synonym t above.

@matthewhammer
Copy link
Contributor

It looks like this is another instance of a Motoko developer wondering about #13

It's good to not feel alone : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants