haskell-style-guide icon indicating copy to clipboard operation
haskell-style-guide copied to clipboard

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

Open hvr opened this issue 10 years ago • 0 comments

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.

hvr avatar Sep 23 '14 06:09 hvr