[generics-rep] Newtypes for deriving via

Đang mở
#241 1 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

  • #37 của @kl0tl — đã đóng, không merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
20/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

status: blocked type: enhancement

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?

Ngôn ngữ chính
PureScript
Star
168
Fork
90
Merge trung bình
3 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của purescript/purescript-prelude

Tất cả issue của purescript/purescript-prelude

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.