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.
data Precision a = Roughly a | Exactly a
data Approximate a = Maybe (Precision a)
Recently I wanted a type that adds another alternative to Maybe,
specifically an approximate result, so I wrote (somewhat without
thinking)
data Approximate a = Roughly a | Maybe a
Haskell does not complain about the type (after all, it just looks like
I'm defining a constructor called Maybe)
I can nest the Maybe in a new type:
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.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 54:25:15 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,563 |