tibbe / haskell-style-guide

A style guide for Haskell code.
959 stars 75 forks source link

Suggestion for `{-# MINIMAL #-}` pragma placement #15

Open hvr opened 10 years ago

hvr commented 10 years ago

The general recommendation seems to be to place pragmas after the entity they apply to. But in case of the {-# MINIMAL #-} pragma, I think the following works best in terms of readability:

class Foldable t where
    {-# MINIMAL foldMap | foldr #-}

    -- | Combine the elements of a structure using a monoid.
    fold :: Monoid m => t m -> m
    fold = foldMap id

   {- long list of other methods -}

    -- | List of elements of a structure.
    toList :: Foldable t => t a -> [a]
    toList t = build (\ c n -> foldr c n t)
    {-# INLINE toList #-}

as opposed to place the {-# MINIMAL #-}-line after the {-# INLINE toList #-}-line.