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


Groups > comp.lang.haskell > #490

Re: Type question

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Mark Carroll <mtbc@bcs.org>
Newsgroups comp.lang.haskell
Subject Re: Type question
Date Mon, 16 Jul 2018 21:05:06 +0100
Organization none
Lines 26
Message-ID <8736wjc5fx.fsf@ixod.org> (permalink)
References <L453D.296188$R51.200199@fx03.iad>
Mime-Version 1.0
Content-Type text/plain
Injection-Info reader02.eternal-september.org; posting-host="d45b13ffb1d8f27ede53fa39a805b4b7"; logging-data="30131"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eVWZLKwWgwKvrdJVs4Sx8"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Cancel-Lock sha1:qrARwgi/fE1XL9sQpIzUuIo7hjQ= sha1:1BtoLJ8Z2j5YilvKb2rG3Yqyerw=
Xref csiph.com comp.lang.haskell:490

Show key headers only | View raw


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 | NextPrevious in thread | Next 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