I cannot wrap my head around how to define a type in Haskell that represents the recursive nature of an HTTP Multipart MIME POST.
In English, a Post is either a list of Headers along with Content of some type, or it's a list of Headers with Content of another Post. But Content can also be a list of Posts.
So I've defined Header
thus:
data Header = Header { hName :: String
, hValue :: String
, hAddl :: [(String,String)] } deriving (Eq, Show)
I guess Content
should be something like:
data Content a = Content a | [Post] deriving (Eq, Show)
Obviously, that fails: parse error in constructor in data/newtype declaration: [Post]
I've defined Post
as:
data Post = Post { pHeaders :: [Header]
, pContent :: [Content] } deriving (Eq, Show)
I'm using Haskell to get a different perspective on my current task, the latest question thereon being here. Just using String
for Content
, I can parse simple POSTs using Parsec. But the goal is to parse complex Posts.
The link above, and the links found at that question, give the context for my current task. I'm a Haskell hobbyist, so please feel free to offer alternatives to the code I've posted here--I'm not married to it, and I'd love to learn. Ultimately, I'll use F#, unless I am unable to deliver, in which case I'll be forced to use C# and an imperative style. I welcome any wisdom or direction that supports a functional solution!