Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.haskell > #488

Type question

Newsgroups comp.lang.haskell
From Black Swan <root@rhok.xyz>
Subject Type question
Message-ID <L453D.296188$R51.200199@fx03.iad> (permalink)
Organization Newshosting.com - Highest quality at a great price! www.newshosting.com
Date 2018-07-16 18:02 +0000

Show all headers | View raw


From:
Black Swan 
Subject:
Haskell question
Date:
07.02.2106 17:28
Newsgroups:
comp.lang.functional


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 | 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?

Back to comp.lang.haskell | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Type question Black Swan <root@rhok.xyz> - 2018-07-16 18:02 +0000
  Re: Type question Mark Carroll <mtbc@bcs.org> - 2018-07-16 20:56 +0100
  Re: Type question Mark Carroll <mtbc@bcs.org> - 2018-07-16 21:05 +0100
    RE: Re: Type question Black Swan <root@rhok.xyz> - 2018-07-17 15:04 +0000
      Re: Type question Mark Carroll <mtbc@bcs.org> - 2018-07-17 16:11 +0100

csiph-web