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: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 05:09:47 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,602 |