[generics-rep] Newtypes for deriving via
Nessuno ha ancora preso questa issue.
- #37 di @kl0tl — chiusa senza merge
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 20/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Ambito
- backend
Direzione di ricerca
Read the issue’s deriving-via examples and the linked PureScript PR #3824 to understand the proposed mechanism. The issue asks for naming guidance for newtypes such as GenericBounded, GenericShow, and GenericEnum; done would mean a naming scheme is agreed on, but the thread has no recorded decision and a linked pull request is closed.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
With deriving via and some newtypes we could simulate defaults methods and alleviate a bit the implementation of typeclasses with generic defaults.
For instance implementing Show, Enum and Bounded:
module Example where
import Data.Enum (class Enum)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Bounded (genericBottom, genericTop)
import Data.Generic.Rep.Enum (genericSucc, genericPred)
import Data.Generic.Rep.Show (genericShow)
data ABC = A | B | C
derive instance eqABC :: Eq ABC
derive instance ordABC :: Ord ABC
derive instance genericABC :: Generic ABC _
instance showABC :: Show ABC where
show = genericShow
instance boundedABC :: Bounded ABC where
top = genericTop
bottom = genericBottom
instance enumABC :: Enum ABC where
succ = genericSucc
pred = genericPred
Could be a bit more compact:
module Example where
import Data.Enum (class Enum)
import Data.Generic.Rep (class Generic)
-import Data.Generic.Rep.Bounded (genericBottom, genericTop)
+import Data.Generic.Rep.Bounded (GenericBounded)
-import Data.Generic.Rep.Enum (genericSucc, genericPred)
+import Data.Generic.Rep.Enum (GenericEnum)
-import Data.Generic.Rep.Show (genericShow)
+import Data.Generic.Rep.Show (GenericShow)
data ABC = A | B | C
derive instance eqABC :: Eq ABC
derive instance ordABC :: Ord ABC
derive instance genericABC :: Generic ABC _
+derive via (GenericShow ABC) instance showABC :: Show ABC
-instance showABC :: Show ABC where
- show = genericShow
+derive via (GenericBounded ABC) instance boundedABC :: Bounded ABC
-instance boundedABC :: Bounded ABC where
- top = genericTop
- bottom = genericBottom
+derive via (GenericEnum ABC) instance enumABC :: Enum ABC
-instance enumABC :: Enum ABC where
- succ = genericSucc
- pred = genericPred
Writing those newtypes is straightforward and I gladly volonteer. The only annoyance is how to name them: GenericBounded isn’t taken but GenericShow and GenericEnum refer to the typeclasses implemented by the generic representation.
Would it be acceptable to rename the typeclasses to GenericRep* and keep Generic* for the newtypes? Or has someone a better naming scheme to propose?
- Lingua principale
- PureScript
- Stelle
- 168
- Fork
- 90
- Merge medio
- 3g 1h
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di purescript/purescript-prelude
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 57/100
purescript/purescript-prelude#317 · 1 reazione ·
-
Int bottom is not safeAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 32/100
purescript/purescript-prelude#312 · 5 commenti ·
-
add liftCompare & friendsAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
purescript/purescript-prelude#310 · 5 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 24/100
purescript/purescript-prelude#308 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
purescript/purescript-prelude#307 · 1 commento · 1 reazione ·
Tutte le issue di purescript/purescript-prelude
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
ManageSieve proxy: a backend's NO/BYE greeting is skipped as a capability line and reported as EOFApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Mend: dependency security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Mend: dependency security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ManageIQ/manageiq-pods#1476 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
prime-radiant-inc/evener#6366 ·
I maintainer di solito rispondono entro 1 giorno