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


Groups > comp.lang.haskell > #565

Re: Nested "Maybe"

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.haskell
Subject Re: Nested "Maybe"
Date 2021-04-09 14:24 -0700
Organization A noiseless patient Spider
Message-ID <87blan883u.fsf@nightsong.com> (permalink)
References <878s5rtb4g.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>   data Approximate a = Roughly a | Exactly (Maybe a)
>
>   f a | a < 0     = Exactly Nothing
>       | a > 10000 = Roughly (sqrt a)
>       | otherwise = Exactly (Just (a / 2))
>
> but I can't help wondering if I'm missing a neater way to do this.

That looks inside out?  I.e. the Maybe should be on the outside.

data Precision a = Roughly a | Exactly a
data Approximate a = Maybe (Precision a)

f a | a < 0 = Nothing
    | a > 10000 = Just (Roughly (sqrt a))
    | otherwise = Just (Exactly (a/2))

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


Thread

Nested "Maybe" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-09 22:13 +0100
  Re: Nested "Maybe" Paul Rubin <no.email@nospam.invalid> - 2021-04-09 14:24 -0700
    Re: Nested "Maybe" Paul Rubin <no.email@nospam.invalid> - 2021-04-09 14:27 -0700
  Re: Nested "Maybe" Mark Carroll <mtbc@bcs.org> - 2021-04-09 17:33 -0400

csiph-web