Git Product home page Git Product logo

hs-ten's Introduction

ten

A mirrored typeclass hierarchy of Functor etc. for (k -> Type) -> Type.

Stack CI

Disclaimer

This is not an officially supported Google product.

Hackage Status

  • ten Uploaded Haddock
  • ten-lens Uploaded Haddock
  • ten-unordered-containers Uploaded Haddock

Overview

This gives equivalents of Functor, Applicative, Foldable, Traversable, and Representable for types whose parameter is a "wrapper" type constructor rather than just a concrete type.

The naming convention Functor10 comes from the fact that it's a functor from the category of objects with one type parameter to the category of objects with zero type parameters. See hakaru for precedent for this naming convention. From there, since everyone will end up pronouncing it "functor-ten", we pick "ten" as the package name and module namespace.

The two categories involved are:

The source category Hask{k}, denoting the category whose objects are Haskell type constructors of kind k -> Type, and whose morphisms m ~> n are quantified functions forall a. m a -> n a. Objects in this category are commonly Functors, although they don't have to be; examples include Identity, Const String, and Maybe. Morphisms in this category are parametric functions, such as maybeToList :: Maybe ~> [] or Const . length :: [] ~> Const Int. Note this is actually a collection of related categories: Type -> Type is a different category from Nat -> Type; for convenience we often hand-wave this fact away and say "the" category. Since these categories' defining characteristic is that their objects have one type parameter, we abbreviate it to "1".

The target category Hask, the normal category of Haskell types and functions. By the same convention as the last paragraph, we abbreviate this category to "0".

Then, functors from Hask{k} to Hask are functors from "1" to "0", and thus we call them Functor10. One common kind of functor between these two categories is "higher-kinded-data" records like data Thing f = Thing (f Int) (f Bool). This kind of usage is the main focus of the library, and has the most fully-formed functionality. Other things exist, too, which might have different instances of f in each value, or even existentially-quantified instances of f. These are available in varying states of completeness.

hs-ten's People

Contributors

awpr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hs-ten's Issues

Incoming breakage from Eq superclass of Hashable

This isn't in a released version yet, but I discovered the incoming breakage when testing against GHC 9.2 with newer-than-Hackage versions of dependencies. Hashable is gaining an Eq superclass, which means the quantified constraints on the Ap instances will no longer work as written.

Can I use Representable10 and Update10 with structures containing lists?

Hi there,

First, congratulations on a really cool package. I’m excited to explore whether it’s a solution to this problem we’ve encountered while building the Semantic framework: we want to generate syntax trees that have shape functors attached to them, but working with these structures in a manner that’s comparably fluent to plain-old-data-types is tricky.

I’ve been experimenting with a JSON grammar, and have run into a problem: I can’t figure out how to specify that one syntax node should contain a list of others. I have these two types:

newtype EscapeSequence (f :: Type -> Type) = EscapeSequence { text :: Ap10 Text f }
  deriving stock (Eq, Ord, Read, Show, Generic, Generic1)
  deriving anyclass (NFData, Hashable)
  deriving (Portray, Diff) via Wrapped Generic (EscapeSequence f)
  deriving (Foldable10, Traversable10, Constrained10 c, Functor10, Applicative10, Representable10, Update10) via Wrapped1 Generic1 EscapeSequence

newtype StringContent (f :: Type -> Type) = StringContents { contents :: EscapeSequence f }
  deriving stock (Eq, Ord, Read, Show, Generic, Generic1)
  deriving anyclass (NFData, Hashable)
  deriving (Portray, Diff) via Wrapped Generic (StringContent f)
  deriving (Foldable10, Traversable10, Constrained10 c, Functor10, Applicative10, Representable10, Update10) via Wrapped1 Generic1 StringContent

and I would like StringContent to contain an [EscapeSequence f], or some sort of structure that allows one StringContent to hold multiple EscapeSequence values. (Note that in this case I could just remove the type parameter from EscapeSequence, but lists etc. appear elsewhere in syntax where this wouldn’t be an option.) I’ve tried using a plain [EscapeSequence f] field, which since [] is not Representable, precludes using Representable10 and Update10. I’ve tried using Cofree, and also tried using Compose and :.: and ListT to glom on an additional list-layer. None of these things seem to work—the only solution I’ve found is to remove the Representable10 and Update10 derivings. While I could dispense with them, it would be a huge win if I could retain that typeclass machinery, as I’d love to use ten-lens. Do you have any suggestions here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.