Skip to content

Instantly share code, notes, and snippets.

@hobwekiva
Last active August 11, 2020 22:08
Show Gist options
  • Save hobwekiva/28dd6a0693c2d92d45528a62f7df9e0e to your computer and use it in GitHub Desktop.
Save hobwekiva/28dd6a0693c2d92d45528a62f7df9e0e to your computer and use it in GitHub Desktop.
  1. def hash(a: A): Int makes me sad. What about hashing to 64 bits or SL2 Fp?
  2. def MapHash[A, B: Hash]: Hash[Map[A, B]] is a bit odd. Why not A: Hash?
  3. reflexiveLaw + symmetryLaw + transitivityLaw is too weak for "equality". This defines a general equivalence relationship only.
  4. val AnyEqual: Equal[Any] is worrisome, considering all the resolution bugs!
  5. val DoubleEqual: Equal[Double] should be implemented using java.lang.Double.doubleToRawLongBits.
  6. A combintation of trait Ord[-A] extends Equal[A] and trait Hash[-A] extends Equal[A] is a recipe for ambigious implicit resolution problem. There is no good solution though (Scato encoding is not modular, compiler plugin requires evil reflection, defining intersection subtypes is not scalable). EDIT: There is HashOrd in the coherent package.
  7. val DoubleOrd: Ord[Double] is good, though there are more than one NaN and I wonder how compare handles those 🤔.
  8. [F[+_]] is making a statement for sure, though I am not sure if it is justified. You can use covariant type constructor as an argument to a typeclass accepting invariant F[_] but not vice versa.
  9. Ord[B].contramap(f) instances violate the laws. Of course it does not matter in this case, but... 👺 At the very least it tells you that something is wrong with the abstractions if we have to coerce them like that. Same thing here.
  10. foldMap(fa)(a => Or(f(a))) is too eager and will always consume the whole F[A] since foldMap is defined through foldLeft. Laziness is hard.
  11. Map[A @uncheckedVariance, B] is almost guaranteed to result in CCEs if someone passes a SortedMap[A, B] in.
  12. Well-known issue with this particular encoding of newtypes is casting wrapping / unwrapping arrays. Consider trait Tag extends Any. The rest of the newtype implementation has too much indirection for me to follow, it's unnecessarily complex, perhaps for educational reasons. Please ask @edmundnoble for a Responsible asInstanceOf User license, and don't be afraid to use it for low-level implementation details.
  13. Equivalence[A, B] should be called Iso[A, B]. Come on, this simplification of the language is going too far 😅!
  14. Debug.Repr is a really cool innovation in this area. But n.startsWith("Tuple") is probably insufficiently precise (think TupleConverterShit).
  15. Map[A, B] won't work with newtypes that require a custom equality or hashing. Not very common, but when it happens (newtypes over Double), you'll know it.
  16. Are people THAT afraid of the word Profunctor?
  17. zio.prelude.coherent is for ... "coherent" typeclasses?
  18. Pretend-"associativity" of Double always makes me sad, but I have not seen a better solution than just ignoring the problem so far. Not a criticism, just a general remark.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment