-
Notifications
You must be signed in to change notification settings - Fork 326
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
Support for type classes #5446
Comments
The blueprint to write type classes in Enso as for Oct 2024: Define API and "Dictionary"Here is a way to define Set type class: from Standard.Base import Error
from Standard.Base.Errors.Common import Type_Error
from Standard.Base.Errors import Illegal_State
type Set a
Value o s:a
is_empty self = self.o.is_empty self.s
contains self e = self.o.contains self.s e
length self = self.o.length self.s
insert self e = Set.Value self.o <| self.o.insert self.s e
union self (other:Set) = if self.o != other.o then Error.throw (Type_Error "Incompatible sets") else
Set.Value self.o <| self.o.union self.s other.s
type Operator a
is_empty (_ : Set) = Error.Throw (Illegal_State.Error "is_empty not implemented")
contains (_ : Set) _ = Error.Throw (Illegal_State.Error "contains not implemented")
length (_ : Set) _ = Error.Throw (Illegal_State.Error "length not implemented")
insert (_ : Set) _ = Error.Throw (Illegal_State.Error "insert not implemented")
union (_ : Set) _ = Error.Throw (Illegal_State.Error "union not implemented") The Implementation with
|
Enso doesn't have special syntax for writing type classes as of Oct 2024. The original design...
...hasn't yet been implemented. Anyway this is the current blueprint to follow when writing type classes as of Oct 2024. There is also
The text was updated successfully, but these errors were encountered: