Working on a Haskell project, I\'m dealing with the Event
data type from the FSNotify package. The constructors for Event
are all:
The simplest way would be to actually reflect the homogenity of the alternatives in the type declaration, instead of just observing it:
data Action = Added | Modified | Removed
data Event = FileEvent Action FilePath UTCTime | OtherEvent ...
f :: Event -> FilePath
f (FileEvent _ path _) = path
In general, Haskell has no way to know that all your constructor alternatives have the same number of arguments and the same type, so no, you can't abstract over the choice of alternative.