Loading...
Loading...
Guides efficient Haskell aligned with GHC practice -- laziness and strictness, purity, fusion, newtypes, pragmas, Core reading, and space-leak avoidance. Use when writing or reviewing Haskell, optimizing or profiling, debugging strictness or memory, or when the user mentions GHC, thunks, foldl vs foldl', list fusion, SPECIALIZE, or UNPACK.
npx skill4agent add kaynetik/skills practical-haskell-O-O2IOnewtype-ddump-simplfoldl'Data.Listfoldlprofilingghc-debugmapfilterfoldrfoldl (+) 0!UNPACKdataINLINEINLINABLESPECIALIZEimport Data.List (foldl')
-- Infinite lists are fine when consumption is bounded.
naturals :: [Integer]
naturals = [1..]
firstTen :: [Integer]
firstTen = take 10 naturals
-- foldl on strict arithmetic often leaks thunks; foldl' forces as it goes.
badSum :: [Int] -> Int
badSum = foldl (+) 0
goodSum :: [Int] -> Int
goodSum = foldl' (+) 0{-# LANGUAGE BangPatterns #-}datasum . map f . filter p-O2length{-# RULES #-}newtype UserId = UserId Int
deriving (Eq, Ord, Show)
newtype Email = Email String
deriving (Eq, Show)newtypeGeneralizedNewtypeDeriving{-# SPECIALIZE #-}{-# INLINABLE #-}ghc -O2 -ddump-simpl -dsuppress-all -dno-suppress-type-signatures YourModule.hscaseletfoldlfoldl'UNPACKINLINEINLINABLESPECIALIZE