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

Add typeclasses #27

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Add typeclasses #27

wants to merge 19 commits into from

Conversation

smpoulsen
Copy link
Owner

@smpoulsen smpoulsen commented Oct 10, 2017

Typeclasses provide a means for ad hoc polymorphism.

Currently blocked pending addition of term rewriting when using typeclass-defined functions implemented in terms of other typeclass-defined functions.

Still needs work, but testing with a basic Num type class and implementation for
Int, seems to be mostly working.

It is still rough around the edges, is likely inefficient, and has dead
code/compiler warnings.
Need to implement type classes before merging this, as operations involving
numbers don't type check.
Adds a test helper to import the prelude. This kills performance and should not
be a long term solution.
The code in this system is very messy and needs cleaned up prior to merging.

Typeclasses are working, at least for the Num, Functor, and Monoid
implementations that are included here. Needs further testing still.
Corrects the substitution for instances of a typeclass
The parenthesized arrow types are "more-lisp-like" at the expense of being more
difficult to read. This changes them to follow more of an infix string
representation.

E.g:
  Old: :t map = Functor f => (-> (-> a b) (-> [f a] [f b]))
  New: :t map = Functor f => (a -> b) -> [f a] -> [f b]
Typeclasses seem solid now. There is still no way to constrain an implementation
to depend on another typeclass, so it is up to the user to make sure that
instances are defined.

Because there is no hoisting/two stage eval, import order still matters.
This loads the prelude (currently typeclasses mostly) when starting the repl,
evaluating files, and running tests.

This is already affecting performance; starting to optimize should be a next
step.
Loading the prelude once, when tests start, and passing that environment to the
test functions is more efficient than loading the prelude for each
file/directory. This cuts more than half the run-time off from prior to this change.
@smpoulsen smpoulsen changed the title Add type classes Add typeclasses Oct 10, 2017
Merge main back into type class branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant