Casey Rodarmor
2008-09-29 16:16:24 UTC
Hej hej!
I was writing some code using Ratio, and even though I know it's
tucked behind an abstraction barrier, I really wanted access to the
Ratio data constructor ':%'. I wrote invertRatio like such:
invertRatio r = denominator r % numerator
But I really wanted to write it like this:
invertRatio (n :% d) = d % n
I understand that exposing ':%' causes problems, since it allows us
not only to pick apart ratios, but to construct bad ones that would
normally be caught when constructed with '%'. (Such as '1:%0'.)
Is there any way to avoid this, while still letting the user benefit
from the nice pattern matching syntax that exposing the data
constructor allows?
Kram,
Casey
I was writing some code using Ratio, and even though I know it's
tucked behind an abstraction barrier, I really wanted access to the
Ratio data constructor ':%'. I wrote invertRatio like such:
invertRatio r = denominator r % numerator
But I really wanted to write it like this:
invertRatio (n :% d) = d % n
I understand that exposing ':%' causes problems, since it allows us
not only to pick apart ratios, but to construct bad ones that would
normally be caught when constructed with '%'. (Such as '1:%0'.)
Is there any way to avoid this, while still letting the user benefit
from the nice pattern matching syntax that exposing the data
constructor allows?
Kram,
Casey