
On Jan 31, 2008 4:10 PM, Johannes Waldmann
Bulat Ziganshin wrote:
(very sound software engineering arguments - can someone with The Force please copy Bulat's mail to Haskell/Category/Style ...)
I agree completely, and just add one remark here :
data Encoding = Encoding { encode :: String -> String , decode :: String -> String }
utf8 = Encoding encodeUtf8 decodeUtf8
this is in fact a method table (Java speak) or a dictionary (Haskell), and Encoding is the interface (class) -
except that we can have local instances by passing around dictionaries explicitly.
This is similar to passing a Comparator object to some sorting routine.
Best regards, Johannes.
PS: go read any honest OO book on the benefits of interface oriented design - they know this stuff - they got there the hard way (that is, via C++ :-)
With this approach I would like some facility (e.g. table) to lookup common encodings as the encoding used for a particular datum is not know at compile time in many applications (e.g. it's read from a HTTP Content-Type header or similar.)
lookupEncoding :: String -> Maybe Encoding
-- Johan