I defined a custom data type that contains one field:
import Data.Set (Set) data GraphEdge a = GraphEdge (Set a)
Defining my own type seems more semantically correct, but it leads to a lot of patterns in my functions. Every time I want to use the built-in functions of Set , I have to expand the internal set and then overwrite it:
import Data.Set (map) modifyItemsSomehow :: Ord a => GraphEdge a -> GraphEdge a modifyItemsSomehow (GraphEdge items) = GraphEdge $ Set.map someFunction items
This could be slightly improved by recording, for example
import Data.Set (Set, map) data GraphEdge a = GraphEdge { unGraphEdge :: Set a } modifyItemsSomehow = GraphEdge . map someFunction . unGraphEdge
but it still seems far from ideal. What is the most idiomatic way to handle this type of template when working with a user data type consisting of a single field?
source share