Haskell is a statically typed, purely functional programming language with type inference and lazy evaluation. It is designed for teaching, research, and industrial applications.
Haskell Anti-Patterns Overview
String Concatenation with ++
++
for repeated string concatenation, as it has O(n²) complexity. Use more efficient data structures like Text
or ByteString
, or techniques like ShowS
or Builder
.Partial Functions
head
, tail
, fromJust
, etc. that can crash on certain inputs. Instead, use pattern matching or return Maybe
or Either
to handle all possible cases.Inefficient List Processing
foldr
, foldl'
, or foldMap
for more efficient processing.Not Using Strictness Annotations
!
) for data fields that should be evaluated eagerly, especially in numeric computations, to avoid space leaks and improve performance.Using String Instead of Text or ByteString
String
(which is a linked list of characters) for text processing. Use Text
or ByteString
for better performance with large text data.Not Using Newtypes
newtype
instead of type
for type aliases to get compile-time type checking and avoid mixing up values of the same underlying type but different semantic meanings.Excessive Use of Point-Free Style
Not Using Record Syntax
Not Using Language Extensions Appropriately
DeriveFunctor
, RecordWildCards
, or OverloadedStrings
to make your code more concise and expressive.Not Using Smart Constructors
Using IO Unnecessarily
Not Using Appropriate Monads
Either
, ExceptT
), configuration (Reader
), or state (State
).Not Using Lenses for Deep Updates
lens
package) for working with nested data structures, especially when you need to update deeply nested fields.Not Using Type Classes Appropriately
Not Using Proper Error Messages
error
or undefined
in production code.Using Lazy I/O
Not Using Proper Project Structure
Not Using Proper Dependency Management
Not Using Proper Testing
Not Using Proper Documentation