fosskers / vectortiles

A native Haskell codec for Mapbox Vector Tiles.
BSD 3-Clause "New" or "Revised" License
20 stars 10 forks source link

Consider a `Protobuf` typefamily #3

Closed fosskers closed 8 years ago

fosskers commented 8 years ago

Something like:

type family Protobuf a
type instance Protobuf VectorTile = RawVectorTile
...

class Protobuffable a where
  fromProtobuf :: Protobuf a -> a
  toProtobuf :: a -> Protobuf a

Although there would be no instance for Features, because of the Layer-Feature coupling.

This addition would remove the arbitrarily named functions like layer and unlayer in favour of the to and from pair. The only change the user would see would be the deprecation of the tile/untile functions in favour of {to,from}Protobuf.

fosskers commented 8 years ago

This would also make the conversion to other backends clearer, since they would have their own toGeoJson, etc, functions, and there wouldn't be a top-level tile function name clash.

fosskers commented 8 years ago

The solution to the explicit @VectorTile problem is to use the type family to supply the relationship both ways, then have two typeclasses: ToProtobuf and FromProtobuf.