Looks good to me.
> +instance (ToMessage a) => ToMessage [a] where
> + toContentType [] = B.pack "text/plain"
> + toContentType xs = toContentType $ head xs
> + toMessage [] = L.empty
> + toMessage xs = L.concat $ map toMessage xs
This can be written as:
toMessage = L.concat . map toMessage
(The empty list case is unnecessary)
> hunk ./happstack-server/src/Happstack/Server/SimpleHTTP.hs 768
> - toMessage [el] = LU.fromString $ H.simpleDoc H.NoStyle $ toHaXmlEl el -- !! OPTIMIZE
> - toMessage x = error ("Happstack.Server.SimpleHTTP 'instance ToMessage [Element]' Can't handle " ++ show x)
> + toMessage el = LU.fromString $ H.simpleDoc H.NoStyle $ toHaXmlEl el -- !! OPTIMIZE
Much better!
G
--
Gregory Collins <gr...@gregorycollins.net>
This would be the basis for a solution for the case of XML, but not
the general case. I think Jeremy's reasoning makes sense here. I was
taking the limited view of trying to solve one user's problem.
getDirectoryContents :: FilePath -> IO [FilePath]
FilePath is just a type synonym for String. Maybe a list of strings
instance is appropriate here?
instance => ToMessage [String] where
Or more generally, maybe for monoids?
instance (ToMessage a, Monoid a) => ToMessage [a] where
But I can see how we might not want either of these.
Well, we already have that instance. But it's not valid for all
lists. Maybe we should either complete the instance, or get rid of
it. I don't mind it being completed as [Element] instead of [a].
> On a related note, I believe the original error on irc was a result of
> this ToMessage instance:
>
> instance (Xml a)=>ToMessage a where
> toContentType = toContentType . toXml
> toMessage = toMessage . toPublicXml
I think you're right about this. I hadn't noticed this instance, and
it does seem like the likely cause of the problem. I think that we
should either improve the error message the user sees in this
situation, or clearly document our reasoning in the code. Since the
average user can't be expected to read the code, I think improving the
error message is the better of the two options.