[generics-rep] Newtypes for deriving via
Ninguém assumiu esta issue ainda.
- #37 de @kl0tl — fechado sem integrar
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 20/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Domínio
- backend
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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?
- Linguagem predominante
- PureScript
- Estrelas
- 168
- Forks
- 90
- Merge médio
- 3d 1h
- PRs com merge (30d)
- 1
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Sem guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de purescript/purescript-prelude
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 57/100
purescript/purescript-prelude#317 · 1 reação ·
-
Int bottom is not safeAberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 32/100
purescript/purescript-prelude#312 · 5 comentários ·
-
add liftCompare & friendsAberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
purescript/purescript-prelude#310 · 5 comentários ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 24/100
purescript/purescript-prelude#308 · 2 comentários ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
purescript/purescript-prelude#307 · 1 comentário · 1 reação ·
Todas as issues de purescript/purescript-prelude
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
ROCm/rocm-libraries#15866 ·
Mantenedores costumam responder em até 2 dias
-
お問い合わせのメール送信に失敗しても成功と表示されるAbertaarea: web
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
inabagumi/shinju-date#6823 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
-
ManageSieve proxy: a backend's NO/BYE greeting is skipped as a capability line and reported as EOFAbertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 82/100
dmtrKovalenko/odiff#191 ·