Skip to content

Commit

Permalink
Add unique identifier to typeclass symbol names (#56)
Browse files Browse the repository at this point in the history
* Add unique identifier to typeclass symbol names

This adds a unique tag to the typeclass symbol names because sometimes
build systems will mangle the class names.

What was happening was that `Functor` and `Filterable` were unique
within their own scopse, so the class name became “e”. That caused
funcadelic to look up the instance for `Functor` and getting
`Filterable` because they both had `"@@funcadelic-0/e"` as their
symbol name

* Check to see if function names are being altered

If they are being altered then we add the uniqueTag to the typeclass
symbol name

* Use Unique Tag for typclass symbol names if mangled
  • Loading branch information
Robdel12 authored and taras committed Jul 6, 2018
1 parent 4bb9b82 commit b287882
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/typeclasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ invariant("name" in Function.prototype && "name" in (function x() {}), `funcadel

const VERSION = 0;

// A function that exists to check if the compiler is crushing
// function names. If it is we need to use `uniqueTag` to make sure
// there's no collisions when looking up `symbolNames`
function isCrushed() {}
let hasBeenMangled = typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed';
let uniqueTag = 0;

export function type(Class) {

let name = Class.name;
let name = hasBeenMangled ? uniqueTag++ : Class.name;

if (!name) {
throw new Error('invalid typeclass name: ' + name);
Expand Down

0 comments on commit b287882

Please sign in to comment.