Black Swan
20180716 17:57:43 UTC
I'm struggling with the following function:
The following declaration works:
data DividedResult = Result Integer  DividedByZero deriving (Eq, Show)
dividedBy num denom =
let
(count,remainder,success) = x num denom 0
in if success then (Result count) else DividedByZero
where
x num denom count
 denom == 0 = (0,0,False)
 num < denom = (count,num,True)
 otherwise = x (num  denom) denom (count + 1)
When I check the type of dividedBy, I get
*Lib> :t dividedBy
dividedBy :: (Num b, Ord b) => b > b > DividedResult
However, if I try to add the type declaration line:
dividedBy :: (Num a, DividedResult b) => a > a > b
The module fails to load, yielding the following error:
Expected a constraint, but DividedResult has kind *
In the type signature:
dividedBy :: (Num a, DividedResult b) => a > a > b

10  dividedBy :: (Num a, DividedResult b) => a > a > b
 ^^^^^^^^^^^^^
Failed, no modules loaded.
Could someone please kindly point out my mistake and suggest a type declaration line that works?
The following declaration works:
data DividedResult = Result Integer  DividedByZero deriving (Eq, Show)
dividedBy num denom =
let
(count,remainder,success) = x num denom 0
in if success then (Result count) else DividedByZero
where
x num denom count
 denom == 0 = (0,0,False)
 num < denom = (count,num,True)
 otherwise = x (num  denom) denom (count + 1)
When I check the type of dividedBy, I get
*Lib> :t dividedBy
dividedBy :: (Num b, Ord b) => b > b > DividedResult
However, if I try to add the type declaration line:
dividedBy :: (Num a, DividedResult b) => a > a > b
The module fails to load, yielding the following error:
Expected a constraint, but DividedResult has kind *
In the type signature:
dividedBy :: (Num a, DividedResult b) => a > a > b

10  dividedBy :: (Num a, DividedResult b) => a > a > b
 ^^^^^^^^^^^^^
Failed, no modules loaded.
Could someone please kindly point out my mistake and suggest a type declaration line that works?