How to use modules in place of Type Classes

David Eger <eger-oTNwCEtKUwI/[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
I'm writing a library to do command line parsing in SML much like
the C getopt() function.  I take a dictionary of expected arguments
and their types and a command line string.  I return a dictionary of
parsed arguments.

I don't really care what sort of dictionary I'm passed.

In order for me to make a generalized GETOPT that accepts any sort of
dictionary, it seems that I have to write my module as a functor, taking
a structure argument and that each of my callers has to explicitly
evaluate the functor.  This means that the implementation information
about the underlying representation of a particular dictionary needs to
be threaded through any code base that uses my library all the way down
to the invocation of getopt().

This seems to add a lot of programmer overhead.  Is there a better way?
Is there any equivalence to the type class sugar of Haskell that I could use?

In practice, do SML users just accept a very specific dictionary and have
the caller do the manual conversions?  Do they functorize everything?

-David

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.