From 953e3eb86b57f468c68d6ec0c651e8b3feda1518 Mon Sep 17 00:00:00 2001 From: Alec Theriault Date: Fri, 20 Jul 2018 03:01:16 -0700 Subject: Refactor handling of parens in types (#874) * Fix type parenthesization in Hoogle backend Ported the logic in the HTML and LaTeX backends for adding in parens into something top-level in 'GhcUtil'. Calling that from the Hoogle backend fixes #873. * Remove parenthesizing logic from LaTeX and XHTML backends Now, the only times that parenthesis in types are added in any backend is through the explicit 'HsParTy' constructor. Precedence is also represented as its own datatype. * List out cases explicitly vs. catch-all * Fix printing of parens for QuantifiedConstraints The priority of printing 'forall' types was just one too high. Fixes #877. * Accept HTML output for quantified contexts test --- hoogle-test/ref/Bug873/test.txt | 26 ++++++++++++++++++++++++++ hoogle-test/ref/type-sigs/test.txt | 4 ++-- hoogle-test/src/Bug873/Bug873.hs | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 hoogle-test/ref/Bug873/test.txt create mode 100644 hoogle-test/src/Bug873/Bug873.hs (limited to 'hoogle-test') diff --git a/hoogle-test/ref/Bug873/test.txt b/hoogle-test/ref/Bug873/test.txt new file mode 100644 index 00000000..19100212 --- /dev/null +++ b/hoogle-test/ref/Bug873/test.txt @@ -0,0 +1,26 @@ +-- Hoogle documentation, generated by Haddock +-- See Hoogle, http://www.haskell.org/hoogle/ + +@package test +@version 0.0.0 + +module Bug873 + +-- | Application operator. This operator is redundant, since ordinary +-- application (f x) means the same as (f $ x). +-- However, $ has low, right-associative binding precedence, so it +-- sometimes allows parentheses to be omitted; for example: +-- +--
+--   f $ g $ h x  =  f (g (h x))
+--   
+-- +-- It is also useful in higher-order situations, such as map +-- ($ 0) xs, or zipWith ($) fs xs. +-- +-- Note that ($) is levity-polymorphic in its result type, so +-- that foo $ True where foo :: Bool -> Int# is well-typed +($) :: () => (a -> b) -> a -> b +infixr 0 $ +($$) :: (a -> b) -> a -> b +infixr 0 $$ diff --git a/hoogle-test/ref/type-sigs/test.txt b/hoogle-test/ref/type-sigs/test.txt index ec5f5043..1209279c 100644 --- a/hoogle-test/ref/type-sigs/test.txt +++ b/hoogle-test/ref/type-sigs/test.txt @@ -6,11 +6,11 @@ module ReaderT newtype ReaderT r m a -ReaderT :: r -> m a -> ReaderT r m a +ReaderT :: (r -> m a) -> ReaderT r m a [runReaderT] :: ReaderT r m a -> r -> m a module ReaderTReexport newtype ReaderT r m a -ReaderT :: r -> m a -> ReaderT r m a +ReaderT :: (r -> m a) -> ReaderT r m a [runReaderT] :: ReaderT r m a -> r -> m a runReaderT :: ReaderT r m a -> r -> m a diff --git a/hoogle-test/src/Bug873/Bug873.hs b/hoogle-test/src/Bug873/Bug873.hs new file mode 100644 index 00000000..3a9a5383 --- /dev/null +++ b/hoogle-test/src/Bug873/Bug873.hs @@ -0,0 +1,5 @@ +module Bug873 (($), ($$)) where +infixr 0 $$ + +($$) :: (a -> b) -> a -> b +f $$ x = f x -- cgit v1.2.3