Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Can I use Representable10 and Update10 with structures containing lists? #7

Description

@patrickt

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions