LeanColls icon indicating copy to clipboard operation
LeanColls copied to clipboard

Map operation class

Open JamesGallicchio opened this issue 1 year ago • 3 comments

Functor only applies to type constructors (Type u -> Type v). So, is insufficient for a general purpose map : (A -> B) -> CA -> CB where perhaps CA and CB cannot contain arbitrary element types.

Example: Functor ByteArray does not typecheck, even though we can give map : (Byte -> Byte) -> ByteArray -> ByteArray

Suggested implementation:

class Map (C : Type w) (τ : Type x) (C' : Type y) (τ' : Type z) where
  map : (f : τ → τ') → C → C'

This conflicts with the current Map class (which is the bag of associations abstraction commonly called a Map in other languages).

We could

  1. Name the new class MapOp? Since we will export MapOp (map) it will still be visible, but with the current naming scheme, theorems about map will end up in the MapOp.theorems_about_map namespace.
  2. Rename current Map to MapBag or similar. I don't .. hate this solution? because it emphasizes the class's relationship to Bag, but this goes against other languages with interfaces named Map.

JamesGallicchio avatar Mar 14 '24 18:03 JamesGallicchio

I haven't yet checked what Haskell libraries do. Could be a useful source.

JamesGallicchio avatar Mar 14 '24 18:03 JamesGallicchio

What about Dict or Dictionary?

sullyj3 avatar Mar 31 '24 06:03 sullyj3

Gonna wait until the 4.8 release to add a Map class, so the deprecation notice sticks around for at least a little while.

JamesGallicchio avatar Apr 22 '24 08:04 JamesGallicchio