Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would love a complete Person example :) #20

Open
silky opened this issue Feb 25, 2024 · 4 comments
Open

Would love a complete Person example :) #20

silky opened this issue Feb 25, 2024 · 4 comments

Comments

@silky
Copy link

silky commented Feb 25, 2024

Hello; thanks for this lovely library!

I'm trying to wrap my mind around it.

In the README, you start with a Person example; but then quickly jump into ASTs.

My usage isn't actually an AST; it's much more like the Person example. I'm here because I couldn't quite get barbies to work ( see jcpetruzza/barbies#47 ).

In my own hacking, I'm trying something like

data Person h = Person
    { height :: h :# Const Double
    , weight :: h :# Const Double
    , name   :: h :# Const Text
    }

person :: Pure # Person
person = Pure $ Person
  { height = Pure $ Const 5.0
  , weight = Pure $ Const 1.0
  , name   = Pure $ Const "name"
  }

maybePerson :: Maybe # Person
maybePerson = undefined

what's not clear to me is how to define the maybePerson type. As-is, it doesn't compile. I think I need to somehow adapt the Maybe type to be a kind of Hyper type; but I'm missing exactly how.

I'd love to know how to do this; and then do barbie-style things such as a bmap which takes, say, an Identity # Person and converts it to a Maybe # Person via runIdentity.

Thanks!

@silky
Copy link
Author

silky commented Feb 25, 2024

Hmm; maybe the answer is this:

data HMaybe a
    = HNothing
    | HJust    (a :# HMaybe)

maybePerson :: HMaybe # Person
maybePerson = HJust $ Person
  { height = HNothing
  , weight = HNothing
  , name   = HJust $ Const "Name"
  }

?

@silky
Copy link
Author

silky commented Feb 25, 2024

I guess I was hoping there was a way to re-use existing types instead of defining my own? But I can live with the fact that there isn't; but I'm sure there's a way to make it work ...

@silky
Copy link
Author

silky commented Feb 25, 2024

I'm fairly sure there has to be a way to define a kind of ToHyper type that would take a Maybe type as an argument; but I'm struggling to make that work ...

@silky
Copy link
Author

silky commented Feb 25, 2024

I feel like I'm missing access to a crucial type variable.

I want to write:

data ToHyper :: (Type -> Type) -> AHyperType -> Type where
  ToHyper :: f :# ToHyper f -> ToHyper f h

but I somehow need to get out the variable of AHyperType and apply f to it; but I'm not sure how.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant