Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.haskell > #490
| From | Mark Carroll <mtbc@bcs.org> |
|---|---|
| Newsgroups | comp.lang.haskell |
| Subject | Re: Type question |
| Date | 2018-07-16 21:05 +0100 |
| Organization | none |
| Message-ID | <8736wjc5fx.fsf@ixod.org> (permalink) |
| References | <L453D.296188$R51.200199@fx03.iad> |
On 16 Jul 2018, Black Swan wrote: > data DividedResult = Result Integer | DividedByZero deriving (Eq, Show) (snip) > *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 (snip) > Could someone please kindly point out my mistake and suggest a type > declaration line that works? Beyond the issues with the code as presented, DividedResult is just an algebraic datatype. The constraint syntax you're using in the type signature is for classes, not types: classes simply limit the types that can be used to fill in the type variables like a and b. Also you do need the Ord because that's what "<" needs. It might help if you back up and let us know what you're hoping this type signature will achieve that the inferred one doesn't. It may help to note that in many places where in C++ or whatever you might use a thing called a class, in Haskell it will still simply be a type, with classes being at another step removed and not always needed in the same way. -- Mark
Back to comp.lang.haskell | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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