optics icon indicating copy to clipboard operation
optics copied to clipboard

Unwrapping newtype should be easier than `coercedTo`.

Open amano-kenji opened this issue 1 year ago • 5 comments

A minimal example of unwrapping a newtype

{-# LANGUAGE TypeApplications #-}
import Optics.Core

newtype Index = Index Int deriving (Show, Eq)

ix :: Index
ix = Index 3

ix2 = ix & coercedTo @Int %~ (*2)

@Int bugs me. When I unwrap a newtype, I shouldn't have to specify the wrapped type.

coerced often fails to infer the right types without explicit type declarations.

amano-kenji avatar Mar 14 '23 07:03 amano-kenji