Skip to content

Change interface? #4

Description

@fmap

Proposal: rather than retrieve generics based on values, we could have the interface provide functions for you, whose values change based on arguments.. Typeclasses are instances of a class Typeclass, which provides an extend method, whereby new instances can be appended. When a typeclass' generic receives a value, it looks for an implementation against the defaults and its extensions, , baulking if it can't find one compatible..

With this, out concat example could be rewritten:

function mconcat (xs) {
  return Foldable.foldr(xs, Monoid.plus, Monoid.zero);
};

Activity

  1. fmap commented on Nov 20, 2013

    @fmap
    MemberAuthor

    While modifying object prototypes would give us a pretty interface, we'd have to worry about conflicts between libraries. @yorickvP has proposed using ES6 WeakMaps instead:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap.
    https://github.com/Benvie/WeakMap.

  2. fmap commented on Dec 1, 2013

    @fmap
    MemberAuthor

    So I figure we'd be providing each typeclass an extensible map, which given some constructor, returns the appropriate function implementations?

    @LeopoldTal How's thinking/coding progressing here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions