Relude Conventions
Setup
Use cabal mixins for project-wide adoption (preferred over NoImplicitPrelude):
cabal
build-depends: base >= 4.14 && < 5, relude >= 1.2 && < 1.3
mixins: base hiding (Prelude)
, relude (Relude as Prelude)
, relude
Key Rules
- •Text everywhere -- never use
Stringexcept for legacy interop - •NonEmpty for non-empty collections -- use
viaNonEmptyto safely bridge from lists - •
readMaybe/readEither-- neverread - •
ordNub/hashNub-- nevernub(O(n^2)) - •
Set.member/HashMap.member-- neverelemon Set/HashSet (compile error in relude) - •
whenM/unlessM-- for monadic conditionals - •
one-- for singleton container construction - •Lifted IO -- use relude's lifted
newIORef,readIORef, etc. directly (noliftIOwrapper needed)
Common Conversions
- •
encodeUtf8/decodeUtf8-- Text <-> ByteString - •
toText/toLText/toString-- between string types - •
toStrict/toLazy-- strict <-> lazy Text
Anti-patterns
- •Using
StringwhenTextis available - •Using
head/tailon[a]instead ofNonEmptyorviaNonEmpty - •Using
liftIO . readIORefinstead of liftedreadIORef - •Importing
PreludealongsideRelude - •Leaving
tracecalls in production code
Reference
For migration guide and complete examples:
- •
references/relude-migration.md