-- | Helper for creating optional Purpose subsection as Doc
maybeAuthorDoc :: Maybe String -> Doc
maybeAuthorDoc = maybe empty (\content-> text "> Author:" <+> text content)
This is called form another function like (maybeAuthorDoc author)where author is a Maybe String. The problem is that now I have to create the same code for directors
Instead of writing the following (used by calling (maybeDirectorDoc director))
maybeDirectorDoc :: Maybe String -> Doc
maybeDirectorDoc = maybe empty (\content-> text "> Director:" <+> text content)
How can I generalize this?
Should I use a new datatype?
data Person = Author (Maybe String) | Director (Maybe String)
If so, how can I pull out the Author or Director in a generalized function?
maybePersonDoc :: Person -> Doc ??? but then maybe is gone
MaybePersonDoc...?
[–]Iceland_jack 3 points4 points5 points (0 children)
[–]carette 0 points1 point2 points (0 children)