I would like to know if it is possible to return a result containing Double variables that were constructed using variables of type class Num. To give an example:
dist :: (Graph g n e, Ord n, Num e) => g -> n -> n -> [Double]
dist graph n1 n2 = loop (nodes graph) where
loop [] = []
loop nodes = [n'] ++ loop (tail nodes) where
n' = if (getDist (head nodes)) == 0) then 1/0 else (getDist (head nodes)) + 1 --1/0 = infinity
I am thinking of a toFractional like function to always provide a double from the if-statement
The
Numclass contains a lot of things that don’t have a sensible conversion toDouble, like complex numbers and other things. If you narrow it down to theRealclass instead, you can userealToFrac.