|
26 | 26 |
|
27 | 27 | import Data.Text.Display.Core
|
28 | 28 | import Data.Text.Display.Generic
|
| 29 | + |
| 30 | +-- $designChoices |
| 31 | +-- |
| 32 | +-- === A “Lawless Typeclass” |
| 33 | +-- |
| 34 | +-- The 'Display' typeclass does not contain any law. This is a controversial choice for some people, |
| 35 | +-- but the truth is that there are not any laws to ask of the consumer that are not already enforced |
| 36 | +-- by the type system and the internals of the 'Data.Text.Internal.Text' type. |
| 37 | +-- |
| 38 | +-- === "🚫 You should not try to display functions!" |
| 39 | +-- |
| 40 | +-- Sometimes, when using the library, you may encounter this message: |
| 41 | +-- |
| 42 | +-- > • 🚫 You should not try to display functions! |
| 43 | +-- > 💡 Write a 'newtype' wrapper that represents your domain more accurately. |
| 44 | +-- > If you are not consciously trying to use `display` on a function, |
| 45 | +-- > make sure that you are not missing an argument somewhere. |
| 46 | +-- |
| 47 | +-- The 'display' library does not allow the definition and usage of 'Display' on |
| 48 | +-- bare function types (@(a -> b)@). |
| 49 | +-- Experience and time have shown that due to partial application being baked in the language, |
| 50 | +-- many users encounter a partial application-related error message when a simple missing |
| 51 | +-- argument to a function is the root cause. |
| 52 | +-- |
| 53 | +-- There may be legitimate uses of a 'Display' instance on a function type. |
| 54 | +-- But these usages are extremely dependent on their domain of application. |
| 55 | +-- That is why it is best to wrap them in a newtype that can better |
| 56 | +-- express and enforce the domain. |
| 57 | +-- |
| 58 | +-- === "🚫 You should not try to display ByteStrings!" |
| 59 | +-- |
| 60 | +-- An arbitrary ByteStrings cannot be safely converted to text without prior knowledge of its encoding. |
| 61 | +-- |
| 62 | +-- As such, in order to avoid dangerously blind conversions, it is recommended to use a specialised |
| 63 | +-- function such as 'Data.Text.Encoding.decodeUtf8'' or 'Data.Text.Encoding.decodeUtf8With' if you wish to turn a UTF8-encoded ByteString |
| 64 | +-- to Text. |
0 commit comments