[Haskell-cafe] Literate Haskell and piecewise construction of
classes/instances
Graham Klyne
gk at ninebynine.org
Fri Nov 5 12:00:14 EST 2004
I'm experimenting with a Literate Haskell style to construct a tutorial
about Description Logics [1][2].
I'm developing the material in small sections, and using examples in the
document to test the code as I go along . I therefore find that I want to
introduce the components of class and instance declarations in pieces,
rather than having the entire declaration in a single place. Am I right in
thinking this is not possible?
For example, I find myself resorting to tricks like this:
[[
So far, a single Description Logic (AL) has been considered. My next step
is to generalize the function interface to a collection of type classes
that can handle arbitrary description logics. The basic ideas of concepts,
roles and interpretations are common to all description logics, so these
are used as defined above. It is the concept descriptions, role descriptions
and associated operations that need to be further abstracted:
- class ConceptExpr c where
- iConcept :: Ord a => TInterpretation a -> c -> Set a
(The full and final definition of ConceptExpr is given later.)
:
]]
and later...
[[
The class interface for concept expressions is therefore extended thus:
> class ConceptExpr c where
> iConcept :: Ord a => TInterpretation a -> c -> Set a
> isSatisfiableWith :: TBox c -> c -> Bool
> isSatisfiableWith t c = not (isSubsumedByWith t c emptyClass)
> isSubsumedByWith :: TBox c -> c -> c -> Bool
> isSubsumedByWith t c d =
> not $ isSatisfiableWith t (intersectClass c (complementClass d))
> emptyClass :: c
> complementClass :: c -> c
> intersectClass :: c -> c -> c
]]
What this suggests to me is that for Literate Haskell it is desirable to
have multiple appearances of a class/instance declaration, constrained so
that one version contains all of the definitions contained in any other
appearance, and no two appearances contain differing definitions for any
component (using a fairly strict syntactic comparison to determine
difference here).
Does this strike any chords with anyone?
#g
--
[1] http://dl.kr.org/ (Description Logics web page)
[2] http://www.ninebynine.org/Software/HaskellDL/DLExploration.lhs (My
tutorial, work-in-progress - implements "structural subsumption" for a
simple Description Logic.)
------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact
More information about the Haskell-Cafe
mailing list