ormolu-0.5.3.0: A formatter for Haskell source code

Safe Haskell | Safe-Inferred
Language | Haskell2010

Ormolu.Fixity

Description

Definitions for fixity analysis.

Synopsis

- data OpName
- pattern OpName :: Text -> OpName
- unOpName :: OpName -> Text
- occOpName :: OccName -> OpName
- data FixityDirection
  - = InfixL
  - | InfixR
  - | InfixN
- data FixityInfo = FixityInfo {
  - fiDirection :: Maybe FixityDirection
  - fiMinPrecedence :: Int
  - fiMaxPrecedence :: Int
  }
- type FixityMap = Map OpName FixityInfo
- data LazyFixityMap
- lookupFixity :: OpName -> LazyFixityMap -> Maybe FixityInfo
- data HackageInfo = HackageInfo (Map PackageName FixityMap) (Map PackageName Int)
- defaultStrategyThreshold :: Float
- defaultFixityInfo :: FixityInfo
- buildFixityMap :: Float -> Set PackageName -> LazyFixityMap
- buildFixityMap' :: Map PackageName FixityMap -> Map PackageName Int -> Set PackageName -> Float -> Set PackageName -> LazyFixityMap
- bootPackages :: Set PackageName
- packageToOps :: Map PackageName FixityMap
- packageToPopularity :: Map PackageName Int

# Documentation

data OpName Source #

An operator name.

#### Instances

Instances details

IsString OpName Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods fromString :: String -> OpName Source #
Show OpName Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods showsPrec :: Int -> OpName -> ShowS Source # show :: OpName -> String Source # showList :: [OpName] -> ShowS Source #
Binary OpName Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods put :: OpName -> Put Source # get :: Get OpName Source # putList :: [OpName] -> Put Source #
Eq OpName Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods (==) :: OpName -> OpName -> Bool Source # (/=) :: OpName -> OpName -> Bool Source #
Ord OpName Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods compare :: OpName -> OpName -> Ordering Source # (<) :: OpName -> OpName -> Bool Source # (<=) :: OpName -> OpName -> Bool Source # (>) :: OpName -> OpName -> Bool Source # (>=) :: OpName -> OpName -> Bool Source # max :: OpName -> OpName -> OpName Source # min :: OpName -> OpName -> OpName Source #

pattern OpName :: Text -> OpName Source #

unOpName :: OpName -> Text Source #

Convert an `OpName` to `Text`.

occOpName :: OccName -> OpName Source #

Convert an 'OccName to an `OpName`.

data FixityDirection Source #

Fixity direction.

Constructors

InfixL |
InfixR |
InfixN |

#### Instances

Instances details

Generic FixityDirection Source # |
Instance details Defined in Ormolu.Fixity.Internal Associated Types type Rep FixityDirection :: Type -> Type Source # Methods from :: FixityDirection -> Rep FixityDirection x Source # to :: Rep FixityDirection x -> FixityDirection Source #
Show FixityDirection Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods showsPrec :: Int -> FixityDirection -> ShowS Source # show :: FixityDirection -> String Source # showList :: [FixityDirection] -> ShowS Source #
Binary FixityDirection Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods put :: FixityDirection -> Put Source # get :: Get FixityDirection Source # putList :: [FixityDirection] -> Put Source #
Eq FixityDirection Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods (==) :: FixityDirection -> FixityDirection -> Bool Source # (/=) :: FixityDirection -> FixityDirection -> Bool Source #
Ord FixityDirection Source # |

Instance details

Defined in Ormolu.Fixity.Internal

Methods

compare :: FixityDirection -> FixityDirection -> Ordering Source #

(<) :: FixityDirection -> FixityDirection -> Bool Source #

(<=) :: FixityDirection -> FixityDirection -> Bool Source #

(>) :: FixityDirection -> FixityDirection -> Bool Source #

(>=) :: FixityDirection -> FixityDirection -> Bool Source #

max :: FixityDirection -> FixityDirection -> FixityDirection Source #

min :: FixityDirection -> FixityDirection -> FixityDirection Source #

type Rep FixityDirection Source # |
Instance details Defined in Ormolu.Fixity.Internal type Rep FixityDirection = D1 ('MetaData "FixityDirection" "Ormolu.Fixity.Internal" "ormolu-0.5.3.0-FuEfS2eynJT1kHaZbWMcjW" 'False) (C1 ('MetaCons "InfixL" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "InfixR" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InfixN" 'PrefixI 'False) (U1 :: Type -> Type)))

data FixityInfo Source #

Fixity information about an infix operator that takes the uncertainty that can arise from conflicting definitions into account.

Constructors

FixityInfo |

Fields

- fiDirection :: Maybe FixityDirection

  Fixity direction if it is known

- fiMinPrecedence :: Int

  Minimum precedence level found in the (maybe conflicting) definitions for the operator (inclusive)

- fiMaxPrecedence :: Int

  Maximum precedence level found in the (maybe conflicting) definitions for the operator (inclusive)

#### Instances

Instances details

Semigroup FixityInfo Source # | Gives the ability to merge two (maybe conflicting) definitions for an operator, keeping the higher level of compatible information from both.
Instance details Defined in Ormolu.Fixity.Internal Methods (<>) :: FixityInfo -> FixityInfo -> FixityInfo Source # sconcat :: NonEmpty FixityInfo -> FixityInfo Source # stimes :: Integral b => b -> FixityInfo -> FixityInfo Source #
Generic FixityInfo Source # |
Instance details Defined in Ormolu.Fixity.Internal Associated Types type Rep FixityInfo :: Type -> Type Source # Methods from :: FixityInfo -> Rep FixityInfo x Source # to :: Rep FixityInfo x -> FixityInfo Source #
Show FixityInfo Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods showsPrec :: Int -> FixityInfo -> ShowS Source # show :: FixityInfo -> String Source # showList :: [FixityInfo] -> ShowS Source #
Binary FixityInfo Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods put :: FixityInfo -> Put Source # get :: Get FixityInfo Source # putList :: [FixityInfo] -> Put Source #
Eq FixityInfo Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods (==) :: FixityInfo -> FixityInfo -> Bool Source # (/=) :: FixityInfo -> FixityInfo -> Bool Source #
Ord FixityInfo Source # |

Instance details

Defined in Ormolu.Fixity.Internal

Methods

compare :: FixityInfo -> FixityInfo -> Ordering Source #

(<) :: FixityInfo -> FixityInfo -> Bool Source #

(<=) :: FixityInfo -> FixityInfo -> Bool Source #

(>) :: FixityInfo -> FixityInfo -> Bool Source #

(>=) :: FixityInfo -> FixityInfo -> Bool Source #

max :: FixityInfo -> FixityInfo -> FixityInfo Source #

min :: FixityInfo -> FixityInfo -> FixityInfo Source #

type Rep FixityInfo Source # |

Instance details

Defined in Ormolu.Fixity.Internal

type Rep FixityInfo = D1 ('MetaData "FixityInfo" "Ormolu.Fixity.Internal" "ormolu-0.5.3.0-FuEfS2eynJT1kHaZbWMcjW" 'False) (C1 ('MetaCons "FixityInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "fiDirection") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe FixityDirection)) :*: (S1 ('MetaSel ('Just "fiMinPrecedence") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "fiMaxPrecedence") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))))

type FixityMap = Map OpName FixityInfo Source #

Map from the operator name to its `FixityInfo`.

data LazyFixityMap Source #

A variant of `FixityMap`, represented as a lazy union of several `FixityMap`s.

#### Instances

Instances details

Show LazyFixityMap Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods showsPrec :: Int -> LazyFixityMap -> ShowS Source # show :: LazyFixityMap -> String Source # showList :: [LazyFixityMap] -> ShowS Source #

lookupFixity :: OpName -> LazyFixityMap -> Maybe FixityInfo Source #

Lookup a `FixityInfo` of an operator. This might have drastically different performance depending on whether this is an "unusual" operator.

data HackageInfo Source #

The map of operators declared by each package and the popularity of each package, if available.

Constructors

HackageInfo |

Fields

- (Map PackageName FixityMap)

  Map from package name to a map from operator name to its fixity

- (Map PackageName Int)

  Map from package name to its 30-days download count from Hackage

#### Instances

Instances details

Generic HackageInfo Source # |
Instance details Defined in Ormolu.Fixity.Internal Associated Types type Rep HackageInfo :: Type -> Type Source # Methods from :: HackageInfo -> Rep HackageInfo x Source # to :: Rep HackageInfo x -> HackageInfo Source #
Binary HackageInfo Source # |
Instance details Defined in Ormolu.Fixity.Internal Methods put :: HackageInfo -> Put Source # get :: Get HackageInfo Source # putList :: [HackageInfo] -> Put Source #
type Rep HackageInfo Source # |

Instance details

Defined in Ormolu.Fixity.Internal

type Rep HackageInfo = D1 ('MetaData "HackageInfo" "Ormolu.Fixity.Internal" "ormolu-0.5.3.0-FuEfS2eynJT1kHaZbWMcjW" 'False) (C1 ('MetaCons "HackageInfo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map PackageName FixityMap)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map PackageName Int))))

defaultStrategyThreshold :: Float Source #

The default value for the popularity ratio threshold, after which a very popular definition from packageToOps will completely rule out conflicting definitions instead of being merged with them.

defaultFixityInfo :: FixityInfo Source #

The lowest level of information we can have about an operator.

buildFixityMap Source #

Arguments

:: Float | Popularity ratio threshold, after which a very popular package will completely rule out conflicting definitions coming from other packages instead of being merged with them
-> Set PackageName | Explicitly known dependencies
-> LazyFixityMap | Resulting map

Build a fixity map using the given popularity threshold and a list of cabal dependencies. Dependencies from the list have higher priority than other packages.

buildFixityMap' Source #

Arguments

:: Map PackageName FixityMap | Map from package to fixity map for operators defined in this package
-> Map PackageName Int | Map from package to popularity
-> Set PackageName | Higher priority packages
-> Float | Popularity ratio threshold, after which a very popular package will completely rule out conflicting definitions coming from other packages instead of being merged with them
-> Set PackageName | Explicitly known dependencies
-> LazyFixityMap | Resulting map

Build a fixity map using the given popularity threshold and a list of cabal dependencies. Dependencies from the list have higher priority than other packages. This specific version of the function allows the user to specify the package databases used to build the final fixity map.

bootPackages :: Set PackageName Source #

List of packages shipped with GHC, for which the download count from Hackage does not reflect their high popularity. See https://github.com/tweag/ormolu/pull/830#issuecomment-986609572. "base" is not is this list, because it is already whitelisted by buildFixityMap'.

packageToOps :: Map PackageName FixityMap Source #

packageToPopularity :: Map PackageName Int Source #