A prototype concept for teaching type-class polymorphic functions

Hey there, For those teaching Haskell and making teaching tools, you might be interested in this mode of presentation of a function: http://chrisdone.com/fmap It's a little slow because the implementation is naive (it abuses my tryhaskell.org server), however the concept is: see what fmap really does by showing what you get when applying it to a variety of different types, including “strange” ones like Const and the function type. A given function has visually evident ways of applying to different data structures. The value changes and so does the type. Challenge: take this ball and run with it to illustrate return and >>= for a number of monads. Maybe, [], LogicT, Either, etc. Given that I've been using Haskell for 6 years and haven't yet written a monad tutorial, I don't want to break that clean sheet now. If that's too hard, there're plenty of simpler classes to experiment with. Some types require special handling to display in an intuitive way, like the ((->) r) example. But ignoring that, if you were sufficiently shrewd, you could automatically generate such an interactive page by taking a given typeclass, asking GHCi or the GHC API for all known instances of that type, which are Showable (or somehow representable) and then enumerating them in this kind of display. Others have suggested a "before and after" side-by-side look. So that's an option to consider. Technically you can get before/after with ‘id’ (a lesson in itself, the identity law!), but a two-column layout is an option. Ciao!
participants (1)
-
Christopher Done