You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Algebra.Graph
import Algebra.Graph.Export.Dot
data SillyList = Slist Int Char deriving (Ord,Eq)
instance Show SillyList where
show (Slist _ c) = show c
v0 = (Slist 0 'a')
v1 = (Slist 1 'a')
v2 = (Slist 2 'b')
v3 = (Slist 3 'c')
g = path [v0,v1,v2,v3]
exportViaShow g results in:
But we want
In graphviz language this is achieved by unique node IDs but labelling them with the show value e.g. 0 [label="a"] (although the hard part here is choosing unique node ID values per vertex for arbitrary types)
The text was updated successfully, but these errors were encountered:
I'd say this is the right behaviour. Your instance Show breaks the unstated (but generally agreed upon) requirement for Show instances: if show x == s then it must be possible to feed s to a Haskell compiler and obtain x back. This might seem like a strange requirement, but it's very useful when you want to show a Haskell expression and use the result as a real Haskell code.
This requirement is often violated, but I'd advise against this, because some useful libraries (for example, Facebook's Haxl) rely on it to generate Haskell code.
Note that a consequence of this requirement is that show should be an injective (or one-to-one) function, which guarantees that this issue will not occur.
If you want to obtain the second graph, you need to use the export function instead, where you are in full control of how labels are assigned.
@jmtd I'm convinced the current behaviour is correct, so I'm closing this issue. Feel free to reopen if you'd like to argue that something should be changed.
Consider
exportViaShow g
results in:But we want
In graphviz language this is achieved by unique node IDs but labelling them with the
show
value e.g.0 [label="a"]
(although the hard part here is choosing unique node ID values per vertex for arbitrary types)The text was updated successfully, but these errors were encountered: