[Haskell-cafe] Manual type-checking in graphs: Avoidable?
jeffbrown.the at gmail.com
Fri Feb 19 02:50:26 UTC 2016
I use FGL, which (roughly) defines type Gr a b as a graph on nodes of type
a and edges of type b.
Suppose you wanted a graph that described which people own which hamsters,
knowing only their name. You would have to make node and edge types like
data GraphNode = Person String | Hamster String
data GraphEdge = Has
where the strings represent their names.
Suppose then you wanted to write a function that, given a person, returns
the names of all their hamsters. To make sure the call makes sense, the
function would have to first check that the input is in fact a person.
Since persons and hamsters are both constructors of the same type, you
can't let Haskell's robust, beautiful type-checking system distinguish them
for you; you've got to write something like "case n of Person _ -> True; _
Is there some way around writing such manual checks?
Jeffrey Benjamin Brown
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe