News for hackers. Stuff that matters.
Re:Hell: A Haskell Shell by joeyh on Friday November 22, 2013 @02:38PM (#6783214)
Typeclasses to the rescue..

    ls :: LsOptions -> IO Listing

    instance ToString Listing where ...

    instance Default LsOptions where def = LsOptions []
Now a single `ls` function can yield regular textual output, or the more specific Listing type can be used if you want to say, map over the files listed.

    toString <$> ls def

    map toUpper . filesListed <$> ls def
The repl can automate the application of toString of course, so the user can just enter `ls def`. Someone better at this than I could probably find a way to make the def parameter be optional, too.

There are no comments on this comment yet.