-
Notifications
You must be signed in to change notification settings - Fork 96
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
example #11
Conversation
public type Comparable<T> = { | ||
compare : (T, T) -> Order; | ||
}; | ||
public type t<T> = makeHeap<T>; |
There was a problem hiding this comment.
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>); |
There was a problem hiding this comment.
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>) { |
There was a problem hiding this comment.
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>) { |
There was a problem hiding this comment.
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.
It looks like this is another instance of a Motoko developer wondering about #13 It's good to not feel alone : ) |
No description provided.