overloaded-0.1: Overloaded pragmas as a plugin

Safe HaskellNone
LanguageHaskell2010

Overloaded.Plugin

Description

Overloaded plugin, which makes magic possible.

Synopsis

Documentation

plugin :: Plugin Source #

Overloaded plugin.

To enable plugin put the following at top of the module:

{-# OPTIONS -fplugin=Overloaded -fplugin-opt=Overloaded:Symbols #-}

At least one option is required, multiple can given either using multiple -fplugin-opt options, or by separating options with colon:

{-# OPTIONS -fplugin=Overloaded -fplugin-opt=Overloaded:Symbols:Numerals #-}

Options also take optional desugaring names, for example

{-# OPTIONS -fplugin=Overloaded -fplugin-opt=Overloaded:Labels=Data.Generics.ProductFields.field #-}

to desugar OverloadedLabels directly into field from generics-lens (no need to import orphan instance!)

Supported options

  • Symbols desugars literal strings to fromSymbol @sym
  • Strings works like built-in OverloadedStrings (but you can use different method than fromString)
  • Numerals desugars literal numbers to fromNumeral @nat
  • Naturals desugars literal numbers to fromNatural nat (i.e. like fromString)
  • Chars desugars literal characters to fromChars c. Note: there isn't type-level alternative: we cannot promote Chars.
  • Lists is not like built-in OverloadedLists, but desugars explicit lists to cons and nil
  • If desugars if-expressions to ifte b t e
  • Labels works like built-in OverloadedLabels (you should enable OverloadedLabels so parser recognises the syntax)

Known limitations

  • Doesn't desugar inside patterns