text:
{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

HsTypes: Abstract syntax: user-defined types
-}

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
                                      -- in module PlaceHolder
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE CPP #-}

module HsTypes (
        HsType(..), LHsType, HsKind, LHsKind,
        HsTyVarBndr(..), LHsTyVarBndr,
        LHsQTyVars(..),
        HsImplicitBndrs(..),
        HsWildCardBndrs(..),
        LHsSigType, LHsSigWcType, LHsWcType,
        HsTupleSort(..),
        Promoted(..),
        HsContext, LHsContext,
        HsTyLit(..),
        HsIPName(..), hsIPNameFS,
        HsAppType(..),LHsAppType,

        LBangType, BangType,
        HsSrcBang(..), HsImplBang(..),
        SrcStrictness(..), SrcUnpackedness(..),
        getBangType, getBangStrictness,

        ConDeclField(..), LConDeclField, pprConDeclFields, updateGadtResult,

        HsConDetails(..),

        FieldOcc(..), LFieldOcc, mkFieldOcc,
        AmbiguousFieldOcc(..), mkAmbiguousFieldOcc,
        rdrNameAmbiguousFieldOcc, selectorAmbiguousFieldOcc,
        unambiguousFieldOcc, ambiguousFieldOcc,

        HsWildCardInfo(..), mkAnonWildCardTy,
        wildCardName, sameWildCard,

        mkHsImplicitBndrs, mkHsWildCardBndrs, hsImplicitBody,
        mkEmptyImplicitBndrs, mkEmptyWildCardBndrs,
        mkHsQTvs, hsQTvExplicit, emptyLHsQTvs, isEmptyLHsQTvs,
        isHsKindedTyVar, hsTvbAllKinded,
        hsScopedTvs, hsWcScopedTvs, dropWildCards,
        hsTyVarName, hsAllLTyVarNames, hsLTyVarLocNames,
        hsLTyVarName, hsLTyVarLocName, hsExplicitLTyVarNames,
        splitLHsInstDeclTy, getLHsInstDeclHead, getLHsInstDeclClass_maybe,
        splitLHsPatSynTy,
        splitLHsForAllTy, splitLHsQualTy, splitLHsSigmaTy,
        splitHsFunType, splitHsAppsTy,
        splitHsAppTys, getAppsTyHead_maybe, hsTyGetAppHead_maybe,
        mkHsOpTy, mkHsAppTy, mkHsAppTys,
        ignoreParens, hsSigType, hsSigWcType,
        hsLTyVarBndrToType, hsLTyVarBndrsToTypes,

        -- Printing
        pprHsType, pprHsForAll, pprHsForAllTvs, pprHsForAllExtra,
        pprHsContext, pprHsContextNoArrow, pprHsContextMaybe,
        isCompoundHsType
    ) where

import GhcPrelude

import {-# SOURCE #-} HsExpr ( HsSplice, pprSplice )

import PlaceHolder ( PlaceHolder(..) )
import HsExtension

import Id ( Id )
import Name( Name )
import RdrName ( RdrName )
import NameSet ( NameSet, emptyNameSet )
import DataCon( HsSrcBang(..), HsImplBang(..),
                SrcStrictness(..), SrcUnpackedness(..) )
import TysPrim( funTyConName )
import Type
import HsDoc
import BasicTypes
import SrcLoc
import Outputable
import FastString
import Maybes( isJust )

import Data.Data hiding ( Fixity, Prefix, Infix )
import Data.Maybe ( fromMaybe )
import Control.Monad ( unless )

{-
************************************************************************
*                                                                      *
\subsection{Bang annotations}
*                                                                      *
************************************************************************
-}

-- | Located Bang Type
type LBangType pass = Located (BangType pass)

-- | Bang Type
type BangType pass  = HsType pass       -- Bangs are in the HsType data type

getBangType :: LHsType a -> LHsType a
getBangType (L _ (HsBangTy _ ty)) = ty
getBangType ty                    = ty

getBangStrictness :: LHsType a -> HsSrcBang
getBangStrictness (L _ (HsBangTy s _)) = s
getBangStrictness _ = (HsSrcBang NoSourceText NoSrcUnpack NoSrcStrict)

{-
************************************************************************
*                                                                      *
\subsection{Data types}
*                                                                      *
************************************************************************

This is the syntax for types as seen in type signatures.

Note [HsBSig binder lists]
~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider a binder (or pattern) decorated with a type or kind,
   \ (x :: a -> a). blah
   forall (a :: k -> *) (b :: k). blah
Then we use a LHsBndrSig on the binder, so that the
renamer can decorate it with the variables bound
by the pattern ('a' in the first example, 'k' in the second),
assuming that neither of them is in scope already
See also Note [Kind and type-variable binders] in RnTypes

Note [HsType binders]
~~~~~~~~~~~~~~~~~~~~~
The system for recording type and kind-variable binders in HsTypes
is a bit complicated.  Here's how it works.

* In a HsType,
     HsForAllTy   represents an /explicit, user-written/ 'forall'
                   e.g.   forall a b. ...
     HsQualTy     represents an /explicit, user-written/ context
                   e.g.   (Eq a, Show a) => ...
                  The context can be empty if that's what the user wrote
  These constructors represent what the user wrote, no more
  and no less.

* HsTyVarBndr describes a quantified type variable written by the
  user.  For example
     f :: forall a (b :: *).  blah
  here 'a' and '(b::*)' are each a HsTyVarBndr.  A HsForAllTy has
  a list of LHsTyVarBndrs.

* HsImplicitBndrs is a wrapper that gives the implicitly-quantified
  kind and type variables of the wrapped thing.  It is filled in by
  the renamer. For example, if the user writes
     f :: a -> a
  the HsImplicitBinders binds the 'a' (not a HsForAllTy!).
  NB: this implicit quantification is purely lexical: we bind any
      type or kind variables that are not in scope. The type checker
      may subsequently quantify over further kind variables.

* HsWildCardBndrs is a wrapper that binds the wildcard variables
  of the wrapped thing.  It is filled in by the renamer
     f :: _a -> _
  The enclosing HsWildCardBndrs binds the wildcards _a and _.

* The explicit presence of these wrappers specifies, in the HsSyn,
  exactly where implicit quantification is allowed, and where
  wildcards are allowed.

* LHsQTyVars is used in data/class declarations, where the user gives
  explicit *type* variable bindings, but we need to implicitly bind
  *kind* variables.  For example
      class C (a :: k -> *) where ...
  The 'k' is implicitly bound in the hsq_tvs field of LHsQTyVars

Note [The wildcard story for types]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Types can have wildcards in them, to support partial type signatures,
like       f :: Int -> (_ , _a) -> _a

A wildcard in a type can be

  * An anonymous wildcard,
        written '_'
    In HsType this is represented by HsWildCardTy.
    After the renamer, this contains a Name which uniquely
    identifies this particular occurrence.

  * A named wildcard,
        written '_a', '_foo', etc
    In HsType this is represented by (HsTyVar "_a")
    i.e. a perfectly ordinary type variable that happens
         to start with an underscore

Note carefully:

* When NamedWildCards is off, type variables that start with an
  underscore really /are/ ordinary type variables.  And indeed, even
  when NamedWildCards is on you can bind _a explicitly as an ordinary
  type variable:
        data T _a _b = MkT _b _a
  Or even:
        f :: forall _a. _a -> _b
  Here _a is an ordinary forall'd binder, but (With NamedWildCards)
  _b is a named wildcard.  (See the comments in Trac #10982)

* All wildcards, whether named or anonymous, are bound by the
  HsWildCardBndrs construct, which wraps types that are allowed
  to have wildcards.

* After type checking is done, we report what types the wildcards
  got unified with.

-}

-- | Located Haskell Context
type LHsContext pass = Located (HsContext pass)
      -- ^ 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnUnit'

      -- For details on above see note [Api annotations] in ApiAnnotation

-- | Haskell Context
type HsContext pass = [LHsType pass]

-- | Located Haskell Type
type LHsType pass = Located (HsType pass)
      -- ^ May have 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnComma' when
      --   in a list

      -- For details on above see note [Api annotations] in ApiAnnotation

-- | Haskell Kind
type HsKind pass = HsType pass

-- | Located Haskell Kind
type LHsKind pass = Located (HsKind pass)
      -- ^ 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnDcolon'

      -- For details on above see note [Api annotations] in ApiAnnotation

--------------------------------------------------
--             LHsQTyVars
--  The explicitly-quantified binders in a data/type declaration

-- | Located Haskell Type Variable Binder
type LHsTyVarBndr pass = Located (HsTyVarBndr pass)
                         -- See Note [HsType binders]

-- | Located Haskell Quantified Type Variables
data LHsQTyVars pass   -- See Note [HsType binders]
  = HsQTvs { hsq_implicit :: PostRn pass [Name]
                -- Implicit (dependent) variables

           , hsq_explicit :: [LHsTyVarBndr pass]
                -- Explicit variables, written by the user
                -- See Note [HsForAllTy tyvar binders]

           , hsq_dependent :: PostRn pass NameSet
               -- Which members of hsq_explicit are dependent; that is,
               -- mentioned in the kind of a later hsq_explicit,
               -- or mentioned in a kind in the scope of this HsQTvs
               -- See Note [Dependent LHsQTyVars] in TcHsType
    }

deriving instance (DataId pass) => Data (LHsQTyVars pass)

mkHsQTvs :: [LHsTyVarBndr GhcPs] -> LHsQTyVars GhcPs
mkHsQTvs tvs = HsQTvs { hsq_implicit = PlaceHolder, hsq_explicit = tvs
                      , hsq_dependent = PlaceHolder }

hsQTvExplicit :: LHsQTyVars pass -> [LHsTyVarBndr pass]
hsQTvExplicit = hsq_explicit

emptyLHsQTvs :: LHsQTyVars GhcRn
emptyLHsQTvs = HsQTvs [] [] emptyNameSet

isEmptyLHsQTvs :: LHsQTyVars GhcRn -> Bool
isEmptyLHsQTvs (HsQTvs [] [] _) = True
isEmptyLHsQTvs _                = False

------------------------------------------------
--            HsImplicitBndrs
-- Used to quantify the implicit binders of a type
--    * Implicit binders of a type signature (LHsSigType/LHsSigWcType)
--    * Patterns in a type/data family instance (HsTyPats)

-- | Haskell Implicit Binders
data HsImplicitBndrs pass thing   -- See Note [HsType binders]
  = HsIB { hsib_vars :: PostRn pass [Name] -- Implicitly-bound kind & type vars
         , hsib_body :: thing              -- Main payload (type or list of types)
         , hsib_closed :: PostRn pass Bool -- Taking the hsib_vars into account,
                                           -- is the payload closed? Used in
                                           -- TcHsType.decideKindGeneralisationPlan
    }
deriving instance (DataId pass, Data thing) => Data (HsImplicitBndrs pass thing)

-- | Haskell Wildcard Binders
data HsWildCardBndrs pass thing
    -- See Note [HsType binders]
    -- See Note [The wildcard story for types]
  = HsWC { hswc_wcs :: PostRn pass [Name]
                -- Wild cards, both named and anonymous
                -- after the renamer

         , hswc_body :: thing
                -- Main payload (type or list of types)
                -- If there is an extra-constraints wildcard,
                -- it's still there in the hsc_body.
    }

deriving instance (DataId pass, Data thing) => Data (HsWildCardBndrs pass thing)

-- | Located Haskell Signature Type
type LHsSigType   pass = HsImplicitBndrs pass (LHsType pass)    -- Implicit only

-- | Located Haskell Wildcard Type
type LHsWcType    pass = HsWildCardBndrs pass (LHsType pass)    -- Wildcard only

-- | Located Haskell Signature Wildcard Type
type LHsSigWcType pass = HsWildCardBndrs pass (LHsSigType pass) -- Both

-- See Note [Representing type signatures]

hsImplicitBody :: HsImplicitBndrs pass thing -> thing
hsImplicitBody (HsIB { hsib_body = body }) = body

hsSigType :: LHsSigType pass -> LHsType pass
hsSigType = hsImplicitBody

hsSigWcType :: LHsSigWcType pass -> LHsType pass
hsSigWcType sig_ty = hsib_body (hswc_body sig_ty)

dropWildCards :: LHsSigWcType pass -> LHsSigType pass
-- Drop the wildcard part of a LHsSigWcType
dropWildCards sig_ty = hswc_body sig_ty

{- Note [Representing type signatures]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HsSigType is used to represent an explicit user type signature
such as   f :: a -> a
     or   g (x :: a -> a) = x

A HsSigType is just a HsImplicitBndrs wrapping a LHsType.
 * The HsImplicitBndrs binds the /implicitly/ quantified tyvars
 * The LHsType binds the /explicitly/ quantified tyvars

E.g. For a signature like
   f :: forall (a::k). blah
we get
   HsIB { hsib_vars = [k]
        , hsib_body = HsForAllTy { hst_bndrs = [(a::*)]
                                 , hst_body = blah }
The implicit kind variable 'k' is bound by the HsIB;
the explicitly forall'd tyvar 'a' is bound by the HsForAllTy
-}

mkHsImplicitBndrs :: thing -> HsImplicitBndrs GhcPs thing
mkHsImplicitBndrs x = HsIB { hsib_body   = x
                           , hsib_vars   = PlaceHolder
                           , hsib_closed = PlaceHolder }

mkHsWildCardBndrs :: thing -> HsWildCardBndrs GhcPs thing
mkHsWildCardBndrs x = HsWC { hswc_body = x
                           , hswc_wcs  = PlaceHolder }

-- Add empty binders.  This is a bit suspicious; what if
-- the wrapped thing had free type variables?
mkEmptyImplicitBndrs :: thing -> HsImplicitBndrs GhcRn thing
mkEmptyImplicitBndrs x = HsIB { hsib_body   = x
                              , hsib_vars   = []
                              , hsib_closed = False }

mkEmptyWildCardBndrs :: thing -> HsWildCardBndrs GhcRn thing
mkEmptyWildCardBndrs x = HsWC { hswc_body = x
                              , hswc_wcs  = [] }

--------------------------------------------------
-- | These names are used early on to store the names of implicit
-- parameters.  They completely disappear after type-checking.
newtype HsIPName = HsIPName FastString
  deriving( Eq, Data )

hsIPNameFS :: HsIPName -> FastString
hsIPNameFS (HsIPName n) = n

instance Outputable HsIPName where
    ppr (HsIPName n) = char '?' <> ftext n -- Ordinary implicit parameters

instance OutputableBndr HsIPName where
    pprBndr _ n   = ppr n         -- Simple for now
    pprInfixOcc  n = ppr n
    pprPrefixOcc n = ppr n

--------------------------------------------------

-- | Haskell Type Variable Binder
data HsTyVarBndr pass
  = UserTyVar        -- no explicit kinding
         (Located (IdP pass))
        -- See Note [Located RdrNames] in HsExpr
  | KindedTyVar
         (Located (IdP pass))
         (LHsKind pass)  -- The user-supplied kind signature
        -- ^
        --  - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen',
        --          'ApiAnnotation.AnnDcolon', 'ApiAnnotation.AnnClose'

        -- For details on above see note [Api annotations] in ApiAnnotation
deriving instance (DataId pass) => Data (HsTyVarBndr pass)

-- | Does this 'HsTyVarBndr' come with an explicit kind annotation?
isHsKindedTyVar :: HsTyVarBndr pass -> Bool
isHsKindedTyVar (UserTyVar {})   = False
isHsKindedTyVar (KindedTyVar {}) = True

-- | Do all type variables in this 'LHsQTyVars' come with kind annotations?
hsTvbAllKinded :: LHsQTyVars pass -> Bool
hsTvbAllKinded = all (isHsKindedTyVar . unLoc) . hsQTvExplicit

-- | Haskell Type
data HsType pass
  = HsForAllTy   -- See Note [HsType binders]
      { hst_bndrs :: [LHsTyVarBndr pass]
                                       -- Explicit, user-supplied 'forall a b c'
      , hst_body  :: LHsType pass      -- body type
      }
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnForall',
      --         'ApiAnnotation.AnnDot','ApiAnnotation.AnnDarrow'
      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsQualTy   -- See Note [HsType binders]
      { hst_ctxt :: LHsContext pass       -- Context C => blah
      , hst_body :: LHsType pass }

  | HsTyVar             Promoted -- whether explicitly promoted, for the pretty
                                 -- printer
                        (Located (IdP pass))
                  -- Type variable, type constructor, or data constructor
                  -- see Note [Promotions (HsTyVar)]
                  -- See Note [Located RdrNames] in HsExpr
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsAppsTy            [LHsAppType pass] -- Used only before renaming,
                                          -- Note [HsAppsTy]
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

  | HsAppTy             (LHsType pass)
                        (LHsType pass)
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsFunTy             (LHsType pass)   -- function type
                        (LHsType pass)
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnRarrow',

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsListTy            (LHsType pass)  -- Element type
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'['@,
      --         'ApiAnnotation.AnnClose' @']'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsPArrTy            (LHsType pass)  -- Elem. type of parallel array: [:t:]
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'[:'@,
      --         'ApiAnnotation.AnnClose' @':]'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsTupleTy           HsTupleSort
                        [LHsType pass]  -- Element types (length gives arity)
    -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'(' or '(#'@,
    --         'ApiAnnotation.AnnClose' @')' or '#)'@

    -- For details on above see note [Api annotations] in ApiAnnotation

  | HsSumTy             [LHsType pass]  -- Element types (length gives arity)
    -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'(#'@,
    --         'ApiAnnotation.AnnClose' '#)'@

    -- For details on above see note [Api annotations] in ApiAnnotation

  | HsOpTy              (LHsType pass) (Located (IdP pass)) (LHsType pass)
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsParTy             (LHsType pass)   -- See Note [Parens in HsSyn] in HsExpr
        -- Parenthesis preserved for the precedence re-arrangement in RnTypes
        -- It's important that a * (b + c) doesn't get rearranged to (a*b) + c!
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'('@,
      --         'ApiAnnotation.AnnClose' @')'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsIParamTy          (Located HsIPName) -- (?x :: ty)
                        (LHsType pass)   -- Implicit parameters as they occur in
                                         -- contexts
      -- ^
      -- > (?x :: ty)
      --
      -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnDcolon'

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsEqTy              (LHsType pass)   -- ty1 ~ ty2
                        (LHsType pass)   -- Always allowed even without
                                         -- TypeOperators, and has special
                                         -- kinding rule
      -- ^
      -- > ty1 ~ ty2
      --
      -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnTilde'

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsKindSig           (LHsType pass)  -- (ty :: kind)
                        (LHsKind pass)  -- A type with a kind signature
      -- ^
      -- > (ty :: kind)
      --
      -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'('@,
      --         'ApiAnnotation.AnnDcolon','ApiAnnotation.AnnClose' @')'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsSpliceTy          (HsSplice pass)   -- Includes quasi-quotes
                        (PostTc pass Kind)
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'$('@,
      --         'ApiAnnotation.AnnClose' @')'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsDocTy             (LHsType pass) LHsDocString -- A documented type
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsBangTy    HsSrcBang (LHsType pass)   -- Bang-style type annotations
      -- ^ - 'ApiAnnotation.AnnKeywordId' :
      --         'ApiAnnotation.AnnOpen' @'{-\# UNPACK' or '{-\# NOUNPACK'@,
      --         'ApiAnnotation.AnnClose' @'#-}'@
      --         'ApiAnnotation.AnnBang' @\'!\'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsRecTy     [LConDeclField pass]    -- Only in data type declarations
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @'{'@,
      --         'ApiAnnotation.AnnClose' @'}'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsCoreTy Type       -- An escape hatch for tunnelling a *closed*
                        -- Core Type through HsSyn.
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsExplicitListTy       -- A promoted explicit list
        Promoted           -- whether explcitly promoted, for pretty printer
        (PostTc pass Kind) -- See Note [Promoted lists and tuples]
        [LHsType pass]
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @"'["@,
      --         'ApiAnnotation.AnnClose' @']'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsExplicitTupleTy      -- A promoted explicit tuple
        [PostTc pass Kind] -- See Note [Promoted lists and tuples]
        [LHsType pass]
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen' @"'("@,
      --         'ApiAnnotation.AnnClose' @')'@

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsTyLit HsTyLit      -- A promoted numeric literal.
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

      -- For details on above see note [Api annotations] in ApiAnnotation

  | HsWildCardTy (HsWildCardInfo pass)  -- A type wildcard
      -- See Note [The wildcard story for types]
      -- ^ - 'ApiAnnotation.AnnKeywordId' : None

      -- For details on above see note [Api annotations] in ApiAnnotation
deriving instance (DataId pass) => Data (HsType pass)

-- Note [Literal source text] in BasicTypes for SourceText fields in
-- the following
-- | Haskell Type Literal
data HsTyLit
  = HsNumTy SourceText Integer
  | HsStrTy SourceText FastString
    deriving Data

newtype HsWildCardInfo pass      -- See Note [The wildcard story for types]
    = AnonWildCard (PostRn pass (Located Name))
      -- A anonymous wild card ('_'). A fresh Name is generated for
      -- each individual anonymous wildcard during renaming
deriving instance (DataId pass) => Data (HsWildCardInfo pass)

-- | Located Haskell Application Type
type LHsAppType pass = Located (HsAppType pass)
      -- ^ 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnSimpleQuote'

-- | Haskell Application Type
data HsAppType pass
  = HsAppInfix (Located (IdP pass)) -- either a symbol or an id in backticks
  | HsAppPrefix (LHsType pass)      -- anything else, including things like (+)
deriving instance (DataId pass) => Data (HsAppType pass)

instance (SourceTextX pass, OutputableBndrId pass)
       => Outputable (HsAppType pass) where
  ppr = ppr_app_ty

{-
Note [HsForAllTy tyvar binders]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
After parsing:
  * Implicit => empty
    Explicit => the variables the user wrote

After renaming
  * Implicit => the *type* variables free in the type
    Explicit => the variables the user wrote (renamed)

Qualified currently behaves exactly as Implicit,
but it is deprecated to use it for implicit quantification.
In this case, GHC 7.10 gives a warning; see
Note [Context quantification] in RnTypes, and Trac #4426.
In GHC 8.0, Qualified will no longer bind variables
and this will become an error.

The kind variables bound in the hsq_implicit field come both
  a) from the kind signatures on the kind vars (eg k1)
  b) from the scope of the forall (eg k2)
Example:   f :: forall (a::k1) b. T a (b::k2)

Note [Unit tuples]
~~~~~~~~~~~~~~~~~~
Consider the type
    type instance F Int = ()
We want to parse that "()"
    as HsTupleTy HsBoxedOrConstraintTuple [],
NOT as HsTyVar unitTyCon

Why? Because F might have kind (* -> Constraint), so we when parsing we
don't know if that tuple is going to be a constraint tuple or an ordinary
unit tuple.  The HsTupleSort flag is specifically designed to deal with
that, but it has to work for unit tuples too.

Note [Promotions (HsTyVar)]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
HsTyVar: A name in a type or kind.
  Here are the allowed namespaces for the name.
    In a type:
      Var: not allowed
      Data: promoted data constructor
      Tv: type variable
      TcCls before renamer: type constructor, class constructor, or promoted data constructor
      TcCls after renamer: type constructor or class constructor
    In a kind:
      Var, Data: not allowed
      Tv: kind variable
      TcCls: kind constructor or promoted type constructor

  The 'Promoted' field in an HsTyVar captures whether the type was promoted in
  the source code by prefixing an apostrophe.

Note [HsAppsTy]
~~~~~~~~~~~~~~~
How to parse

  Foo * Int

? Is it `(*) Foo Int` or `Foo GHC.Types.* Int`? There's no way to know until renaming.
So we just take type expressions like this and put each component in a list, so be
sorted out in the renamer. The sorting out is done by RnTypes.mkHsOpTyRn. This means
that the parser should never produce HsAppTy or HsOpTy.

Note [Promoted lists and tuples]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Notice the difference between
   HsListTy    HsExplicitListTy
   HsTupleTy   HsExplicitListTupleTy

E.g.    f :: [Int]                      HsListTy

        g3  :: T '[]                   All these use
        g2  :: T '[True]                  HsExplicitListTy
        g1  :: T '[True,False]
        g1a :: T [True,False]             (can omit ' where unambiguous)

  kind of T :: [Bool] -> *        This kind uses HsListTy!

E.g.    h :: (Int,Bool)                 HsTupleTy; f is a pair
        k :: S '(True,False)            HsExplicitTypleTy; S is indexed by
                                           a type-level pair of booleans
        kind of S :: (Bool,Bool) -> *   This kind uses HsExplicitTupleTy

Note [Distinguishing tuple kinds]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Apart from promotion, tuples can have one of three different kinds:

        x :: (Int, Bool)                -- Regular boxed tuples
        f :: Int# -> (# Int#, Int# #)   -- Unboxed tuples
        g :: (Eq a, Ord a) => a         -- Constraint tuples

For convenience, internally we use a single constructor for all of these,
namely HsTupleTy, but keep track of the tuple kind (in the first argument to
HsTupleTy, a HsTupleSort). We can tell if a tuple is unboxed while parsing,
because of the #. However, with -XConstraintKinds we can only distinguish
between constraint and boxed tuples during type checking, in general. Hence the
four constructors of HsTupleSort:

        HsUnboxedTuple                  -> Produced by the parser
        HsBoxedTuple                    -> Certainly a boxed tuple
        HsConstraintTuple               -> Certainly a constraint tuple
        HsBoxedOrConstraintTuple        -> Could be a boxed or a constraint
                                        tuple. Produced by the parser only,
                                        disappears after type checking
-}

-- | Haskell Tuple Sort
data HsTupleSort = HsUnboxedTuple
                 | HsBoxedTuple
                 | HsConstraintTuple
                 | HsBoxedOrConstraintTuple
                 deriving Data

-- | Promoted data types.
data Promoted = Promoted
              | NotPromoted
              deriving (Data, Eq, Show)

-- | Located Constructor Declaration Field
type LConDeclField pass = Located (ConDeclField pass)
      -- ^ May have 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnComma' when
      --   in a list

      -- For details on above see note [Api annotations] in ApiAnnotation

-- | Constructor Declaration Field
data ConDeclField pass  -- Record fields have Haddoc docs on them
  = ConDeclField { cd_fld_names :: [LFieldOcc pass],
                                   -- ^ See Note [ConDeclField passs]
                   cd_fld_type :: LBangType pass,
                   cd_fld_doc  :: Maybe LHsDocString }
      -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnDcolon'

      -- For details on above see note [Api annotations] in ApiAnnotation
deriving instance (DataId pass) => Data (ConDeclField pass)

instance (SourceTextX pass, OutputableBndrId pass)
       => Outputable (ConDeclField pass) where
  ppr (ConDeclField fld_n fld_ty _) = ppr fld_n <+> dcolon <+> ppr fld_ty

-- HsConDetails is used for patterns/expressions *and* for data type
-- declarations
-- | Haskell Constructor Details
data HsConDetails arg rec
  = PrefixCon [arg]             -- C p1 p2 p3
  | RecCon    rec               -- C { x = p1, y = p2 }
  | InfixCon  arg arg           -- p1 `C` p2
  deriving Data

instance (Outputable arg, Outputable rec)
         => Outputable (HsConDetails arg rec) where
  ppr (PrefixCon args) = text "PrefixCon" <+> ppr args
  ppr (RecCon rec)     = text "RecCon:" <+> ppr rec
  ppr (InfixCon l r)   = text "InfixCon:" <+> ppr [l, r]

-- Takes details and result type of a GADT data constructor as created by the
-- parser and rejigs them using information about fixities from the renamer.
-- See Note [Sorting out the result type] in RdrHsSyn
updateGadtResult
  :: (Monad m)
     => (SDoc -> m ())
     -> SDoc
     -> HsConDetails (LHsType GhcRn) (Located [LConDeclField GhcRn])
                     -- ^ Original details
     -> LHsType GhcRn -- ^ Original result type
     -> m (HsConDetails (LHsType GhcRn) (Located [LConDeclField GhcRn]),
           LHsType GhcRn)
updateGadtResult failWith doc details ty
  = do { let (arg_tys, res_ty) = splitHsFunType ty
             badConSig         = text "Malformed constructor signature"
       ; case details of
           InfixCon {}  -> pprPanic "updateGadtResult" (ppr ty)

           RecCon {}    -> do { unless (null arg_tys)
                                       (failWith (doc <+> badConSig))
                              ; return (details, res_ty) }

           PrefixCon {} -> return (PrefixCon arg_tys, res_ty)}

{-
Note [ConDeclField passs]
~~~~~~~~~~~~~~~~~~~~~~~~~

A ConDeclField contains a list of field occurrences: these always
include the field label as the user wrote it.  After the renamer, it
will additionally contain the identity of the selector function in the
second component.

Due to DuplicateRecordFields, the OccName of the selector function
may have been mangled, which is why we keep the original field label
separately.  For example, when DuplicateRecordFields is enabled

    data T = MkT { x :: Int }

gives

    ConDeclField { cd_fld_names = [L _ (FieldOcc "x" $sel:x:MkT)], ... }.
-}

-----------------------
-- A valid type must have a for-all at the top of the type, or of the fn arg
-- types

---------------------
hsWcScopedTvs :: LHsSigWcType GhcRn -> [Name]
-- Get the lexically-scoped type variables of a HsSigType
--  - the explicitly-given forall'd type variables
--  - the implicitly-bound kind variables
--  - the named wildcars; see Note [Scoping of named wildcards]
-- because they scope in the same way
hsWcScopedTvs sig_ty
  | HsWC { hswc_wcs = nwcs, hswc_body = sig_ty1 }  <- sig_ty
  , HsIB { hsib_vars = vars, hsib_body = sig_ty2 } <- sig_ty1
  = case sig_ty2 of
      L _ (HsForAllTy { hst_bndrs = tvs }) -> vars ++ nwcs ++
                                              map hsLTyVarName tvs
               -- include kind variables only if the type is headed by forall
               -- (this is consistent with GHC 7 behaviour)
      _                                    -> nwcs

hsScopedTvs :: LHsSigType GhcRn -> [Name]
-- Same as hsWcScopedTvs, but for a LHsSigType
hsScopedTvs sig_ty
  | HsIB { hsib_vars = vars,  hsib_body = sig_ty2 } <- sig_ty
  , L _ (HsForAllTy { hst_bndrs = tvs }) <- sig_ty2
  = vars ++ map hsLTyVarName tvs
  | otherwise
  = []

{- Note [Scoping of named wildcards]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
  f :: _a -> _a
  f x = let g :: _a -> _a
            g = ...
        in ...

Currently, for better or worse, the "_a" variables are all the same. So
although there is no explicit forall, the "_a" scopes over the definition.
I don't know if this is a good idea, but there it is.
-}

---------------------
hsTyVarName :: HsTyVarBndr pass -> IdP pass
hsTyVarName (UserTyVar (L _ n))     = n
hsTyVarName (KindedTyVar (L _ n) _) = n

hsLTyVarName :: LHsTyVarBndr pass -> IdP pass
hsLTyVarName = hsTyVarName . unLoc

hsExplicitLTyVarNames :: LHsQTyVars pass -> [IdP pass]
-- Explicit variables only
hsExplicitLTyVarNames qtvs = map hsLTyVarName (hsQTvExplicit qtvs)

hsAllLTyVarNames :: LHsQTyVars GhcRn -> [Name]
-- All variables
hsAllLTyVarNames (HsQTvs { hsq_implicit = kvs, hsq_explicit = tvs })
  = kvs ++ map hsLTyVarName tvs

hsLTyVarLocName :: LHsTyVarBndr pass -> Located (IdP pass)
hsLTyVarLocName = fmap hsTyVarName

hsLTyVarLocNames :: LHsQTyVars pass -> [Located (IdP pass)]
hsLTyVarLocNames qtvs = map hsLTyVarLocName (hsQTvExplicit qtvs)

-- | Convert a LHsTyVarBndr to an equivalent LHsType.
hsLTyVarBndrToType :: LHsTyVarBndr pass -> LHsType pass
hsLTyVarBndrToType = fmap cvt
  where cvt (UserTyVar n) = HsTyVar NotPromoted n
        cvt (KindedTyVar (L name_loc n) kind)
          = HsKindSig (L name_loc (HsTyVar NotPromoted (L name_loc n))) kind

-- | Convert a LHsTyVarBndrs to a list of types.
-- Works on *type* variable only, no kind vars.
hsLTyVarBndrsToTypes :: LHsQTyVars pass -> [LHsType pass]
hsLTyVarBndrsToTypes (HsQTvs { hsq_explicit = tvbs }) = map hsLTyVarBndrToType tvbs

---------------------
wildCardName :: HsWildCardInfo GhcRn -> Name
wildCardName (AnonWildCard  (L _ n)) = n

-- Two wild cards are the same when they have the same location
sameWildCard :: Located (HsWildCardInfo pass)
             -> Located (HsWildCardInfo pass) -> Bool
sameWildCard (L l1 (AnonWildCard _))   (L l2 (AnonWildCard _))   = l1 == l2

ignoreParens :: LHsType pass -> LHsType pass
ignoreParens (L _ (HsParTy ty))                      = ignoreParens ty
ignoreParens (L _ (HsAppsTy [L _ (HsAppPrefix ty)])) = ignoreParens ty
ignoreParens ty                                      = ty

{-
************************************************************************
*                                                                      *
                Building types
*                                                                      *
************************************************************************
-}

mkAnonWildCardTy :: HsType GhcPs
mkAnonWildCardTy = HsWildCardTy (AnonWildCard PlaceHolder)

mkHsOpTy :: LHsType pass -> Located (IdP pass) -> LHsType pass -> HsType pass
mkHsOpTy ty1 op ty2 = HsOpTy ty1 op ty2

mkHsAppTy :: LHsType pass -> LHsType pass -> LHsType pass
mkHsAppTy t1 t2 = addCLoc t1 t2 (HsAppTy t1 t2)

mkHsAppTys :: LHsType pass -> [LHsType pass] -> LHsType pass
mkHsAppTys = foldl mkHsAppTy

{-
************************************************************************
*                                                                      *
                Decomposing HsTypes
*                                                                      *
************************************************************************
-}

---------------------------------
-- splitHsFunType decomposes a type (t1 -> t2 ... -> tn)
-- Breaks up any parens in the result type:
--      splitHsFunType (a -> (b -> c)) = ([a,b], c)
-- Also deals with (->) t1 t2; that is why it only works on LHsType Name
--   (see Trac #9096)
splitHsFunType :: LHsType GhcRn -> ([LHsType GhcRn], LHsType GhcRn)
splitHsFunType (L _ (HsParTy ty))
  = splitHsFunType ty

splitHsFunType (L _ (HsFunTy x y))
  | (args, res) <- splitHsFunType y
  = (x:args, res)

splitHsFunType orig_ty@(L _ (HsAppTy t1 t2))
  = go t1 [t2]
  where  -- Look for (->) t1 t2, possibly with parenthesisation
    go (L _ (HsTyVar _ (L _ fn))) tys | fn == funTyConName
                                 , [t1,t2] <- tys
                                 , (args, res) <- splitHsFunType t2
                                 = (t1:args, res)
    go (L _ (HsAppTy t1 t2)) tys = go t1 (t2:tys)
    go (L _ (HsParTy ty))    tys = go ty tys
    go _                     _   = ([], orig_ty)  -- Failure to match

splitHsFunType other = ([], other)

--------------------------------
-- | Retrieves the head of an HsAppsTy, if this can be done unambiguously,
-- without consulting fixities.
getAppsTyHead_maybe :: [LHsAppType pass]
                    -> Maybe (LHsType pass, [LHsType pass], LexicalFixity)
getAppsTyHead_maybe tys = case splitHsAppsTy tys of
  ([app1:apps], []) ->  -- no symbols, some normal types
    Just (mkHsAppTys app1 apps, [], Prefix)
  ([app1l:appsl, app1r:appsr], [L loc op]) ->  -- one operator
    Just ( L loc (HsTyVar NotPromoted (L loc op))
         , [mkHsAppTys app1l appsl, mkHsAppTys app1r appsr], Infix)
  _ -> -- can't figure it out
    Nothing

-- | Splits a [HsAppType pass] (the payload of an HsAppsTy) into regions of
-- prefix types (normal types) and infix operators.
-- If @splitHsAppsTy tys = (non_syms, syms)@, then @tys@ starts with the first
-- element of @non_syms@ followed by the first element of @syms@ followed by
-- the next element of @non_syms@, etc. It is guaranteed that the non_syms list
-- has one more element than the syms list.
splitHsAppsTy :: [LHsAppType pass] -> ([[LHsType pass]], [Located (IdP pass)])
splitHsAppsTy = go [] [] []
  where
    go acc acc_non acc_sym [] = (reverse (reverse acc : acc_non), reverse acc_sym)
    go acc acc_non acc_sym (L _ (HsAppPrefix ty) : rest)
      = go (ty : acc) acc_non acc_sym rest
    go acc acc_non acc_sym (L _ (HsAppInfix op) : rest)
      = go [] (reverse acc : acc_non) (op : acc_sym) rest

-- Retrieve the name of the "head" of a nested type application
-- somewhat like splitHsAppTys, but a little more thorough
-- used to examine the result of a GADT-like datacon, so it doesn't handle
-- *all* cases (like lists, tuples, (~), etc.)
hsTyGetAppHead_maybe :: LHsType pass
                     -> Maybe (Located (IdP pass), [LHsType pass])
hsTyGetAppHead_maybe = go []
  where
    go tys (L _ (HsTyVar _ ln))          = Just (ln, tys)
    go tys (L _ (HsAppsTy apps))
      | Just (head, args, _) <- getAppsTyHead_maybe apps
                                         = go (args ++ tys) head
    go tys (L _ (HsAppTy l r))           = go (r : tys) l
    go tys (L _ (HsOpTy l (L loc n) r))  = Just (L loc n, l : r : tys)
    go tys (L _ (HsParTy t))             = go tys t
    go tys (L _ (HsKindSig t _))         = go tys t
    go _   _                             = Nothing

splitHsAppTys :: LHsType GhcRn -> [LHsType GhcRn]
              -> (LHsType GhcRn, [LHsType GhcRn])
  -- no need to worry about HsAppsTy here
splitHsAppTys (L _ (HsAppTy f a)) as = splitHsAppTys f (a:as)
splitHsAppTys (L _ (HsParTy f))   as = splitHsAppTys f as
splitHsAppTys f                   as = (f,as)

--------------------------------
splitLHsPatSynTy :: LHsType pass
                 -> ( [LHsTyVarBndr pass]    -- universals
                    , LHsContext pass        -- required constraints
                    , [LHsTyVarBndr pass]    -- existentials
                    , LHsContext pass        -- provided constraints
                    , LHsType pass)          -- body type
splitLHsPatSynTy ty = (univs, reqs, exis, provs, ty4)
  where
    (univs, ty1) = splitLHsForAllTy ty
    (reqs,  ty2) = splitLHsQualTy ty1
    (exis,  ty3) = splitLHsForAllTy ty2
    (provs, ty4) = splitLHsQualTy ty3

splitLHsSigmaTy :: LHsType pass
                -> ([LHsTyVarBndr pass], LHsContext pass, LHsType pass)
splitLHsSigmaTy ty
  | (tvs, ty1)  <- splitLHsForAllTy ty
  , (ctxt, ty2) <- splitLHsQualTy ty1
  = (tvs, ctxt, ty2)

splitLHsForAllTy :: LHsType pass -> ([LHsTyVarBndr pass], LHsType pass)
splitLHsForAllTy (L _ (HsForAllTy { hst_bndrs = tvs, hst_body = body })) = (tvs, body)
splitLHsForAllTy (L _ (HsParTy t)) = splitLHsForAllTy t
splitLHsForAllTy body              = ([], body)

splitLHsQualTy :: LHsType pass -> (LHsContext pass, LHsType pass)
splitLHsQualTy (L _ (HsQualTy { hst_ctxt = ctxt, hst_body = body })) = (ctxt,     body)
splitLHsQualTy (L _ (HsParTy t)) = splitLHsQualTy t
splitLHsQualTy body              = (noLoc [], body)

splitLHsInstDeclTy :: LHsSigType GhcRn
                   -> ([Name], LHsContext GhcRn, LHsType GhcRn)
-- Split up an instance decl type, returning the pieces
splitLHsInstDeclTy (HsIB { hsib_vars = itkvs
                         , hsib_body = inst_ty })
  | (tvs, cxt, body_ty) <- splitLHsSigmaTy inst_ty
  = (itkvs ++ map hsLTyVarName tvs, cxt, body_ty)
         -- Return implicitly bound type and kind vars
         -- For an instance decl, all of them are in scope

getLHsInstDeclHead :: LHsSigType pass -> LHsType pass
getLHsInstDeclHead inst_ty
  | (_tvs, _cxt, body_ty) <- splitLHsSigmaTy (hsSigType inst_ty)
  = body_ty

getLHsInstDeclClass_maybe :: LHsSigType pass -> Maybe (Located (IdP pass))
-- Works on (HsSigType RdrName)
getLHsInstDeclClass_maybe inst_ty
  = do { let head_ty = getLHsInstDeclHead inst_ty
       ; (cls, _) <- hsTyGetAppHead_maybe head_ty
       ; return cls }

{-
************************************************************************
*                                                                      *
                FieldOcc
*                                                                      *
************************************************************************
-}

-- | Located Field Occurrence
type LFieldOcc pass = Located (FieldOcc pass)

-- | Field Occurrence
--
-- Represents an *occurrence* of an unambiguous field.  We store
-- both the 'RdrName' the user originally wrote, and after the
-- renamer, the selector function.
data FieldOcc pass = FieldOcc { rdrNameFieldOcc  :: Located RdrName
                                 -- ^ See Note [Located RdrNames] in HsExpr
                              , selectorFieldOcc :: PostRn pass (IdP pass)
                              }
deriving instance Eq (PostRn pass (IdP pass))  => Eq  (FieldOcc pass)
deriving instance Ord (PostRn pass (IdP pass)) => Ord (FieldOcc pass)
deriving instance (DataId pass) => Data (FieldOcc pass)

instance Outputable (FieldOcc pass) where
  ppr = ppr . rdrNameFieldOcc

mkFieldOcc :: Located RdrName -> FieldOcc GhcPs
mkFieldOcc rdr = FieldOcc rdr PlaceHolder

-- | Ambiguous Field Occurrence
--
-- Represents an *occurrence* of a field that is potentially
-- ambiguous after the renamer, with the ambiguity resolved by the
-- typechecker.  We always store the 'RdrName' that the user
-- originally wrote, and store the selector function after the renamer
-- (for unambiguous occurrences) or the typechecker (for ambiguous
-- occurrences).
--
-- See Note [HsRecField and HsRecUpdField] in HsPat and
-- Note [Disambiguating record fields] in TcExpr.
-- See Note [Located RdrNames] in HsExpr
data AmbiguousFieldOcc pass
  = Unambiguous (Located RdrName) (PostRn pass (IdP pass))
  | Ambiguous   (Located RdrName) (PostTc pass (IdP pass))
deriving instance DataId pass => Data (AmbiguousFieldOcc pass)

instance Outputable (AmbiguousFieldOcc pass) where
  ppr = ppr . rdrNameAmbiguousFieldOcc

instance OutputableBndr (AmbiguousFieldOcc pass) where
  pprInfixOcc  = pprInfixOcc . rdrNameAmbiguousFieldOcc
  pprPrefixOcc = pprPrefixOcc . rdrNameAmbiguousFieldOcc

mkAmbiguousFieldOcc :: Located RdrName -> AmbiguousFieldOcc GhcPs
mkAmbiguousFieldOcc rdr = Unambiguous rdr PlaceHolder

rdrNameAmbiguousFieldOcc :: AmbiguousFieldOcc pass -> RdrName
rdrNameAmbiguousFieldOcc (Unambiguous (L _ rdr) _) = rdr
rdrNameAmbiguousFieldOcc (Ambiguous   (L _ rdr) _) = rdr

selectorAmbiguousFieldOcc :: AmbiguousFieldOcc GhcTc -> Id
selectorAmbiguousFieldOcc (Unambiguous _ sel) = sel
selectorAmbiguousFieldOcc (Ambiguous   _ sel) = sel

unambiguousFieldOcc :: AmbiguousFieldOcc GhcTc -> FieldOcc GhcTc
unambiguousFieldOcc (Unambiguous rdr sel) = FieldOcc rdr sel
unambiguousFieldOcc (Ambiguous   rdr sel) = FieldOcc rdr sel

ambiguousFieldOcc :: FieldOcc pass -> AmbiguousFieldOcc pass
ambiguousFieldOcc (FieldOcc rdr sel) = Unambiguous rdr sel

{-
************************************************************************
*                                                                      *
\subsection{Pretty printing}
*                                                                      *
************************************************************************
-}

instance (SourceTextX pass, OutputableBndrId pass)
       => Outputable (HsType pass) where
    ppr ty = pprHsType ty

instance Outputable HsTyLit where
    ppr = ppr_tylit

instance (SourceTextX pass, OutputableBndrId pass)
       => Outputable (LHsQTyVars pass) where
    ppr (HsQTvs { hsq_explicit = tvs }) = interppSP tvs

instance (SourceTextX pass, OutputableBndrId pass)
       => Outputable (HsTyVarBndr pass) where
    ppr (UserTyVar n)     = ppr n
    ppr (KindedTyVar n k) = parens $ hsep [ppr n, dcolon, ppr k]

instance (Outputable thing) => Outputable (HsImplicitBndrs pass thing) where
    ppr (HsIB { hsib_body = ty }) = ppr ty

instance (Outputable thing) => Outputable (HsWildCardBndrs pass thing) where
    ppr (HsWC { hswc_body = ty }) = ppr ty

instance Outputable (HsWildCardInfo pass) where
    ppr (AnonWildCard _)  = char '_'

pprHsForAll :: (SourceTextX pass, OutputableBndrId pass)
            => [LHsTyVarBndr pass] -> LHsContext pass -> SDoc
pprHsForAll = pprHsForAllExtra Nothing

-- | Version of 'pprHsForAll' that can also print an extra-constraints
-- wildcard, e.g. @_ => a -> Bool@ or @(Show a, _) => a -> String@. This
-- underscore will be printed when the 'Maybe SrcSpan' argument is a 'Just'
-- containing the location of the extra-constraints wildcard. A special
-- function for this is needed, as the extra-constraints wildcard is removed
-- from the actual context and type, and stored in a separate field, thus just
-- printing the type will not print the extra-constraints wildcard.
pprHsForAllExtra :: (SourceTextX pass, OutputableBndrId pass)
                 => Maybe SrcSpan -> [LHsTyVarBndr pass] -> LHsContext pass
                 -> SDoc
pprHsForAllExtra extra qtvs cxt
  = pprHsForAllTvs qtvs <+> pprHsContextExtra show_extra (unLoc cxt)
  where
    show_extra = isJust extra

pprHsForAllTvs :: (SourceTextX pass, OutputableBndrId pass)
               => [LHsTyVarBndr pass] -> SDoc
pprHsForAllTvs qtvs
  | null qtvs = whenPprDebug (forAllLit <+> dot)
  | otherwise = forAllLit <+> interppSP qtvs <> dot

pprHsContext :: (SourceTextX pass, OutputableBndrId pass)
             => HsContext pass -> SDoc
pprHsContext = maybe empty (<+> darrow) . pprHsContextMaybe

pprHsContextNoArrow :: (SourceTextX pass, OutputableBndrId pass)
                    => HsContext pass -> SDoc
pprHsContextNoArrow = fromMaybe empty . pprHsContextMaybe

pprHsContextMaybe :: (SourceTextX pass, OutputableBndrId pass)
                  => HsContext pass -> Maybe SDoc
pprHsContextMaybe []         = Nothing
pprHsContextMaybe [L _ pred] = Just $ ppr_mono_ty pred
pprHsContextMaybe cxt        = Just $ parens (interpp'SP cxt)

-- For use in a HsQualTy, which always gets printed if it exists.
pprHsContextAlways :: (SourceTextX pass, OutputableBndrId pass)
                   => HsContext pass -> SDoc
pprHsContextAlways []  = parens empty <+> darrow
pprHsContextAlways [L _ ty] = ppr_mono_ty ty <+> darrow
pprHsContextAlways cxt = parens (interpp'SP cxt) <+> darrow

-- True <=> print an extra-constraints wildcard, e.g. @(Show a, _) =>@
pprHsContextExtra :: (SourceTextX pass, OutputableBndrId pass)
                  => Bool -> HsContext pass -> SDoc
pprHsContextExtra show_extra ctxt
  | not show_extra
  = pprHsContext ctxt
  | null ctxt
  = char '_' <+> darrow
  | otherwise
  = parens (sep (punctuate comma ctxt')) <+> darrow
  where
    ctxt' = map ppr ctxt ++ [char '_']

pprConDeclFields :: (SourceTextX pass, OutputableBndrId pass)
                 => [LConDeclField pass] -> SDoc
pprConDeclFields fields = braces (sep (punctuate comma (map ppr_fld fields)))
  where
    ppr_fld (L _ (ConDeclField { cd_fld_names = ns, cd_fld_type = ty,
                                 cd_fld_doc = doc }))
        = ppr_names ns <+> dcolon <+> ppr ty <+> ppr_mbDoc doc
    ppr_names [n] = ppr n
    ppr_names ns = sep (punctuate comma (map ppr ns))

{-
Note [Printing KindedTyVars]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Trac #3830 reminded me that we should really only print the kind
signature on a KindedTyVar if the kind signature was put there by the
programmer.  During kind inference GHC now adds a PostTcKind to UserTyVars,
rather than converting to KindedTyVars as before.

(As it happens, the message in #3830 comes out a different way now,
and the problem doesn't show up; but having the flag on a KindedTyVar
seems like the Right Thing anyway.)
-}

-- Printing works more-or-less as for Types

pprHsType :: (SourceTextX pass, OutputableBndrId pass) => HsType pass -> SDoc
pprHsType ty = ppr_mono_ty ty

ppr_mono_lty :: (SourceTextX pass, OutputableBndrId pass)
             => LHsType pass -> SDoc
ppr_mono_lty ty = ppr_mono_ty (unLoc ty)

ppr_mono_ty :: (SourceTextX pass, OutputableBndrId pass)
            => HsType pass -> SDoc
ppr_mono_ty (HsForAllTy { hst_bndrs = tvs, hst_body = ty })
  = sep [pprHsForAllTvs tvs, ppr_mono_lty ty]

ppr_mono_ty (HsQualTy { hst_ctxt = L _ ctxt, hst_body = ty })
  = sep [pprHsContextAlways ctxt, ppr_mono_lty ty]

ppr_mono_ty (HsBangTy b ty)     = ppr b <> ppr_mono_lty ty
ppr_mono_ty (HsRecTy flds)      = pprConDeclFields flds
ppr_mono_ty (HsTyVar NotPromoted (L _ name))= pprPrefixOcc name
ppr_mono_ty (HsTyVar Promoted (L _ name))
  = space <> quote (pprPrefixOcc name)
                         -- We need a space before the ' above, so the parser
                         -- does not attach it to the previous symbol
ppr_mono_ty (HsFunTy ty1 ty2)   = ppr_fun_ty ty1 ty2
ppr_mono_ty (HsTupleTy con tys) = tupleParens std_con (pprWithCommas ppr tys)
  where std_con = case con of
                    HsUnboxedTuple -> UnboxedTuple
                    _              -> BoxedTuple
ppr_mono_ty (HsSumTy tys)       = tupleParens UnboxedTuple (pprWithBars ppr tys)
ppr_mono_ty (HsKindSig ty kind) = parens (ppr_mono_lty ty <+> dcolon <+> ppr kind)
ppr_mono_ty (HsListTy ty)       = brackets (ppr_mono_lty ty)
ppr_mono_ty (HsPArrTy ty)       = paBrackets (ppr_mono_lty ty)
ppr_mono_ty (HsIParamTy n ty)   = (ppr n <+> dcolon <+> ppr_mono_lty ty)
ppr_mono_ty (HsSpliceTy s _)    = pprSplice s
ppr_mono_ty (HsCoreTy ty)       = ppr ty
ppr_mono_ty (HsExplicitListTy Promoted _ tys)
  = quote $ brackets (interpp'SP tys)
ppr_mono_ty (HsExplicitListTy NotPromoted _ tys)
  = brackets (interpp'SP tys)
ppr_mono_ty (HsExplicitTupleTy _ tys) = quote $ parens (interpp'SP tys)
ppr_mono_ty (HsTyLit t)         = ppr_tylit t
ppr_mono_ty (HsWildCardTy {})   = char '_'

ppr_mono_ty (HsEqTy ty1 ty2)
  = ppr_mono_lty ty1 <+> char '~' <+> ppr_mono_lty ty2

ppr_mono_ty (HsAppsTy tys)
  = hsep (map (ppr_app_ty . unLoc) tys)

ppr_mono_ty (HsAppTy fun_ty arg_ty)
  = hsep [ppr_mono_lty fun_ty, ppr_mono_lty arg_ty]

ppr_mono_ty (HsOpTy ty1 (L _ op) ty2)
  = sep [ ppr_mono_lty ty1
        , sep [pprInfixOcc op, ppr_mono_lty ty2 ] ]

ppr_mono_ty (HsParTy ty)
  = parens (ppr_mono_lty ty)
  -- Put the parens in where the user did
  -- But we still use the precedence stuff to add parens because
  --    toHsType doesn't put in any HsParTys, so we may still need them

ppr_mono_ty (HsDocTy ty doc)
  -- AZ: Should we add parens?  Should we introduce "-- ^"?
  = ppr_mono_lty ty <+> ppr (unLoc doc)
  -- we pretty print Haddock comments on types as if they were
  -- postfix operators

--------------------------
ppr_fun_ty :: (SourceTextX pass, OutputableBndrId pass)
           => LHsType pass -> LHsType pass -> SDoc
ppr_fun_ty ty1 ty2
  = let p1 = ppr_mono_lty ty1
        p2 = ppr_mono_lty ty2
    in
    sep [p1, text "->" <+> p2]

--------------------------
ppr_app_ty :: (SourceTextX pass, OutputableBndrId pass)
           => HsAppType pass -> SDoc
ppr_app_ty (HsAppInfix (L _ n))                  = pprInfixOcc n
ppr_app_ty (HsAppPrefix (L _ (HsTyVar NotPromoted (L _ n))))
  = pprPrefixOcc n
ppr_app_ty (HsAppPrefix (L _ (HsTyVar Promoted  (L _ n))))
  = space <> quote (pprPrefixOcc n) -- We need a space before the ' above, so
                                    -- the parser does not attach it to the
                                    -- previous symbol
ppr_app_ty (HsAppPrefix ty) = ppr_mono_lty ty

--------------------------
ppr_tylit :: HsTyLit -> SDoc
ppr_tylit (HsNumTy _ i) = integer i
ppr_tylit (HsStrTy _ s) = text (show s)

-- | Return True for compound types that will need parens.
isCompoundHsType :: LHsType pass -> Bool
isCompoundHsType (L _ HsAppTy{} ) = True
isCompoundHsType (L _ HsAppsTy{}) = True
isCompoundHsType (L _ HsEqTy{}  ) = True
isCompoundHsType (L _ HsFunTy{} ) = True
isCompoundHsType (L _ HsOpTy{}  ) = True
isCompoundHsType _                = False


Home » Where are the voices for radiotherapy?
It is not well publicised – but the main two treatments that cure a cancer are surgery and radiotherapy. Why then does radiotherapy come second or third in most people's minds as a cancer treatment? This article explores these issues, and the lack of investment in all aspects of Radiotherapy.
With the technical knowledge of the experts in The Nottingham Oncology Group, and the latest Radiotherapy technology and techniques (Image Guided Volumetric Arc Therapy) at The Park Cancer Centre, private patients can be assured of the very highest quality radiotherapy.


Erynnis persius is a member of the family Hesperiidae, a type of butterfly called skippers, that is small and very dark. The wings are rounded with a wingspan of 29 to 42 mm, with a brown-black upperside and a lighter underside. The upper forewings have light markings that look grey and mottled near the tip and a row of translucent spots before the mottled grey. They have a robust body and antennae are slender with a hooked club tip. Males have dark hindleg plumes and raised white hairs on the forewing. Males also have yellow scent scales in a costal fold. Females have a more predominate mottle grey color on the tip of the forewing and larger translucent spots near the middle of the forewing, which are diminished or absent on the male. Females have a patch of scent cells on the seventh abdominal segment.
Eggs are pale yellow-green or pale yellow and will turn reddish.
Larvae are pale green with tiny white dots, with a dark green middorsal line and yellowish dorsal line. The head is yellowish to dark reddish brown.
Breeding takes place during the spring and early summer.
Bridgett Winkels (author), Minnesota State University, Mankato, Robert Sorensen (editor), Minnesota State University, Mankato, Angela Miner (editor), Animal Diversity Web Staff.
Barton, B. 2007. "Special animal abstract for Persius duskywing (Erynnis persius persius). Michigan Natural Features Inventory. Lansing, MI. 2 pp." (On-line). Accessed March 28, 2013 at http://mnfi.anr.msu.edu/abstracts/zoology/Erynnis_persius_persius.pdf.
Macy, R., H. Shepard. 1941. Butterflies: A handbook of the butterflies of the United States, Complete for the Region North of the Potomac and Ohio Rivers and East of Dakotas. Minneapolis: The University of Minnesota Press.
Minnesota Department of Natural Resources, 2013. "Erynnis persius (Scudder, 1863) Persius Duskywing" (On-line). Accessed March 24, 2013 at http://www.dnr.state.mn.us/rsg/profile.html?action=elementDetail&selectedElement=IILEP37170.
NatureServe, 2013. "NatureServe Explorer: An online encyclopedia of life [web application]. Version 7.1. NatureServe, Arlington, Virginia" (On-line). Accessed March 26, 2013 at http://www.natureserve.org/explorer/servlet/NatureServe?sourceTemplate=tabular_report.wmt&loadTemplate=species_RptComprehensive.wmt&selectedReport=RptComprehensive.wmt&summaryView=tabular_report.wmt&elKey=118199&paging=home&save=true&startIndex=1&nextStartIndex=1&reset=false&offPageSelectedElKey=118199&offPageSelectedElType=species&offPageYesNo=true&post_processes=&radiobutton=radiobutton&selectedIndexes=118199&selectedIndexes=120580&selectedIndexes=740442&selectedIndexes=120042.
Opler, P., L. Kelly, N. Thomas. 2012. "Butterflies and Moths of North America" (On-line). Accessed March 25, 2013 at http://www.butterfliesandmoths.org/species/Erynnis-persius.
Shepherd, M. 2005. "Skippers: Persius duskywing (Erynnis persius persius)" (On-line). The Xerces Society for Invertebrate Conservation. Accessed March 24, 2013 at http://www.xerces.org/persius-duskywing/.
Shuey, J., J. Calhoun, D. Iftner. 1987. Butterflies that are Endangered, Threatened, and of Special Concern in Ohio. Ohio J. Sci., 87 (4):: 98-106.


During the first week of DAD's existence, we looked at the EDM tracks that Major League Baseball players were using as walk-up songs in 2012. Since then, we've seen EDM creeping into the MLB world slowly, whether its Afrojack playing at the MLB Fan Cave on opening day or W&W playing a special July 4 show after a Phillies game. As 2013 is the year that EDM's rise takes it further into the mainstream, we decided to look at the tracks that players used in 2013, and we must admit: while we're not surprised that Skrillex's "Bangarang" and Flux Pavilion's "I Can't Stop" got a lot of love, the inclusion of the likes of RL Grime, Calvin Harris, and Kavinsky surprised us. Take a look at what EDM moved MLB players in 2013.


Product categories of Electronic Camera Flashlight, we are specialized manufacturers from China, Electronic Camera Flashlight, Digital Camera Flashlight suppliers/factory, wholesale high-quality products of Camera Flash Lamp R & D and manufacturing, we have the perfect after-sales service and technical support. Look forward to your cooperation!
Camera Flash Lamp is a portable electronic light, which can be assembled on a camera or held by hands. Camera flash lamp uses generally electricity to start flash powder burning, to provide a brief sudden burst of bright light. Camera flash lamps are used for a light source when photography at a place with dim light. We have rich experience in the mold design and manufacturing for all plastic components in the camera area.


Andre Pittman and Gregory Cornes are on a mission to rid Washington of opportunistic vermin. But their target isn't corrupt officials or shady political fixers: It's literally rats.
The Washington Post determined Matt Kownacki lodged the most rat complaints after examining about 15,000 rodent-related calls over more than five years.


text:
Racing on ice
After the tragedy at their station, Brazilian researchers discuss how to product science that is more competitive in Antarctica
Fabrício Marques
Atmospherical Sci.GeologyOceanography
ROSALINDA MONTONEThe Comandante Ferraz Station in December 2006: 60 modules formed a villageROSALINDA MONTONE
The reconstruction of the Comandante Ferraz Station, the Brazilian research base in Antarctica, destroyed by a fire on the morning of February 25, will only begin in two years' time and is expected to be complete by 2016. The tragedy, in which two soldiers died, was caused by a fire in power generators and had at least one immediate effect. It re-launched the debate about the Brazilian research ambitions on the frozen continent and the strategies necessary for the work to gain more relevance. The scientists agree that the station should be rebuilt in such a way as to increase safety and guarantee special support for the researchers. Until now, the complex and costly supply logistics and staff transport in the hands of the Navy often left the scientific goals in second place.
There is also a common understanding that the financing model for research in Antarctica, based on public notices of the National Scientific and Technological Development Council (CNPq), which sponsor projects for a two-year term, calls for improvement. It needs to guarantee resources for long-term projects, especially for programs concerned with climate change data. Although not broadly know, Antarctica's influence on Brazil's climate is comparable with that of the Amazon. "Climate change is a major research topic in Antarctica involving areas such as glaciology, meteorology and biology," said Antonio Carlos Rocha-Campos, a retired professor from the Biosciences and Geosciences Institute at USP and the university's Antarctica Research Center coordinator. With a 13.6 million square kilometer area that is almost entirely covered by glaciers, Antarctica is the highest, coldest and driest continent, and it experiences the strongest winds on the planet.
Jefferson Cardia Simões, a glaciologist, a Federal University of Rio Grande do Sul (UFRGS) professor and the first Brazilian to reach the South Pole by land in a scientific expedition in 2004, believes that a new research management model is also desirable in Antarctica. "It isn't a question of merely having a new station, but rather of rebuilding it with a certain aspects in mind" says Simões, and he mentions a few: cooperation with other countries, allowing cost sharing and raising research quality, expedition camp support in other regions, and making the researchers' work more rational. "The scientific community needs to make decisions about station management and about research on Antarctica. Today, logistics, operated by the Navy, and science, in the hand of the researchers, compete with one another. On a daily basis, priorities get lost because of too much demand," the researcher says. The number of Brazilians involved in research on Antarctica has grown. Therefore, the pressure to spend entire seasons on the continent, with all the associated costs and logistics, has grown stronger. "It's impossible for everyone to go out into the field every year. There's a time to collect data and another one to analyze it. And there's research that can be done without going to Antarctica, merely using data collected there" says the glaciologist.
Historically, the bottleneck of the Brazilian Antarctic Program (Proantar) used to be the possibility to visit the station.
ARMANDO HADANO/INPEUSP researchers collect data close to the station: 40% of the research projects were affectedARMANDO HADANO/INPE
There are some 250 Brazilian researchers currently involved in studying this frozen continent. The station has the capacity to accommodate about 20% of this number. It is not always possible to enjoy the full potential on the base. In 2009, the Navy incorporated a polar ship, Almirante Maximiano, for its work in the region. However, in 2011, she practically worked on her own as Ary Rongel, the oceanographic ship supporting the station, had been damaged. Those who do manage to secure a spot on the station also face uncertainties . "I've already spent an entire week without being able to go out due to weather conditions, unfavorable for data collection" says Rosalinda Montone, the USP Oceanographic Institute's professor whose group lost a significant portion of their data about organic pollutants in marine environment to the fire this summer. "We will only be able to recover a small part of it," she says.
A place on the ship and in the station
The chance to travel on two Navy ships and spend a season in the station is usually reserved for projects included in CNPq's periodic announcements and, more recently, in the two National Science and Technology Institutes (INCT) dedicated to Antarctic research. One of the latter focuses on the role that the mass of ice has on the local climate and studies the fluctuation of the Antarctic climate and its influence on Brazil. The other focuses on the impact of human activity on the Antarctic environment. "The selection of projects is very strict and we have moved towards creating networks instead of stimulating the work of individual researchers," says Jefferson Simões.
There is a recurring complaint about lack of investment in long-term projects. "The fact that one of the National Institute for Space Research (INPE) groups was not selected in CNPq's final announcement meant that we had to interrupt a set of meteorological data from the station as there was no one to collect it " says Ronald Buss de Souza, oceanographer and head of INPE's Antarctic program. Ilana Wainer, a professor at USP's Oceanographic Institute, emphasizes the importance of funding data collection that will benefit groups looking for information about the continent without necessarily going there every summer. "We've never been as well financed as now, but it takes more than two-year projects to ensure the monitoring of climate variables. It would be important to have continuous funding," said Ilana, whose work on modeling the Antarctic climate depends to a large extent on Southern Ocean data and on the variation in the area of sea ice. She is greatly dependent on the availability of two Navy ships, which are important for collecting data about the ocean. The station fire and the use of ships for logistics is likely to compromise one of Ilana's projects, Paleoantar, which expected to obtain ice samples to try to understand the so-called defrost pulsation, a possible trigger for climate variations.
She says, however, that Brazil does not need to invest alone and mentions the Southern Ocean Observing System (Soos). This newly created, multidisciplinary network aims to conduct Southern Ocean observations to supply data on climate change, rising sea levels and the impact of global warming on marine ecosystems for various research lines. "Just one country can't do it," she says. She reminds us that studies on climate processes on a local scale are on the edge of a breakthrough and that computer models are having a difficulty simulating the interaction between the climate on Antarctica and the Southern hemisphere. In one example of research that can benefit these models, Ilana's team, in cooperation with researchers from Rio de Janeiro and France, came to the conclusion that the expansion of the hole in the ozone layer over Antarctica in the 1980s led to a wind regime change on the frozen continent with an impact on sea surface temperature in Bahia. "We found a cause and effect relationship between the decline of corals and the growth of the ozone hole. The hole increased the temperature difference between the Antarctic and the tropics intensifying the wind and there was a decrease in the growth of corals in Bahia. Although the gap has diminished, it is not clear if the coral situation has improved. The effects of global warming may have compensated, despite the winds returning to normal. "
Over the past two years, USP's Rocha-Campos also called for international cooperation to carry out his research. He is counting on the backup from an Argentine base and benefitting from the cooperation with the Argentine Antarctic Institute. "We've already collected rock samples on King George Island, not far from the Brazilian station, on other occasions. For the research to move forward, we need to visit other places," says the professor. A group of researchers under his lead has recently identified a glacial structure essential to clarify the paleoclimatic history of Antarctica during the Miocene (about 15 million years ago). The structure, called a glacial clasts pavement , proves that there has been a period of expansion of the West Antarctic ice cap. Rocha-Campos and other Brazilian researchers are in favor of obtaining funds so that Brazil can participate in the program Antarctic Drilling (ANDRILL), an international consortium that has been carrying out geological surveys in the Antarctic continental coast. "If we manage to raise funds to participate, we will enter the mainstream of geological research in Antarctica," he says.
Situated in the hottest part of the Antarctic continent, on King George Island, the Comandante Ferraz station guaranteed easy access for the two Brazilian ships. Several other countries have set up base in the region for a reason. It is in an open bay with broad beaches, which favors logistics and reduces costs. At the same time, it was able to support restricted sets of research studies, such as, for example, those in the field of marine biology, which were affected by most by the fire. Comprising over 60 interconnected modules, it grew over time into a village on the coast. In the winter, only a smaller number of researchers remained at the base. During the cold season, access was not possible by ship, as these vessels only go to the continent between October and April, so the base was visited by the airplanes of the Brazilian Air Force (FAB). "The location is also ideal due to its proximity to two lakes – sources of fresh water," says Rosalinda Montone from USP, who has been to Antarctica 17 times.
FABIO MELO FONTESThe inauguration of the Brazilian Station in 1984: researchers travelled at the Navy's invitationFABIO MELO FONTES
The tragedy interrupted 40% of Brazilian research in Antarctica – a sign that the country's scientific presence on the continent was not exclusively dependent on the logistics structure managed by the Navy. On the one hand, data collection modules located between 300 meters and one kilometer from the burnt base were spared. On the other, there has been a steady increase in the research carried out off the base. Jefferson Cardia Simões' expedition to the geographic South Pole in late 2004, where he collected ice testimonies (cylinders), depended on a logistics schedule outside of what the Navy offered – involving flights by Chilean airplanes and renting a polar tractor together with other researchers. In January, a team led by Heitor Evangelista from the State University of Rio de Janeiro (UERJ) and Jefferson Simões installed Cristofera I – the first Brazilian scientific module obtaining weather data inside the Antarctic continent, located 2.5 thousand kilometers to the south of the station.
The 1982 expedition
The history of Brazilian research funding in Antarctica has several phases. In 1975, Brazil signed the Antarctic Treaty, which dedicated the continent to peaceful activities, in particular scientific research. The country conducted its first expedition in 1982. At the advent of Proantar in 1984 and the inauguration of the Comandante Ferraz station, it was the Navy itself who called for researchers to work in the region through the Inter-ministerial Commission for Sea Resources (CIRM). "The research program was ordered by CIRM, which invited selected institutions and sought to lead research in certain areas," says Ronald Buss de Souza. It is was back then that institutions such as Inpe and the Oceanographic and Earth Sciences Institutes at USP were incorporated into the research effort. USP's oceanographic ship, Captain W. Besnard, made six trips to Antarctica in the 1980s aiding the researchers along with the Navy's Baron de Tefé.
Proantar's second phase began in 1991when the Navy decided to withdraw from research and only take on the logistics of trips to the base. CNPq took over the research. "There was already a critical mass to compete in announcements and CNPq began evaluating projects according to scientific productivity," said Souza. It was not an easy time. "The bride was beautiful but it came without a dowry," says Professor Rocha-Campos. CNPq's resources were limited so that the Ministry of Environment's involvement in Proantar brought relief in a third phase of Antarctic research funding. As determined in a protocol signed by Brazil, the research started to be monitored to reduce its environmental impact.
In the most recent, fourth stage, CNPq released bids to select projects and two National Institutes of Science and Technology were created. The latter work as virtual networks of excellence and are maintained by CNPq and by state foundations that support research. New research groups, mainly from Rio Grande do Sul, were formed over time. "Unlike what happened in the 1980s, when scientists made concessions in their research to include Antarctica, we now have a generation of scientists dedicated to research on the continent. This critical mass pushed for more resources and opportunity to conduct their studies," says Jefferson Simões.
MARIA ROSA PEDREIRO/UFPRThe station in flames: two casualties and reconstruction forecast to be ready in 2016MARIA ROSA PEDREIRO/UFPR
The United States, Britain, Japan and Germany invest the most in research about the Antarctic. "They are the first line of research with stations in different parts of Antarctica and icebreakers capable of reaching them," says Jefferson Simões. China and India rank second, as they have multiplied their investments in the region recently, in addition to France, Norway and Russia. Brazil, with its increase in research groups in recent years, would be in the third platoon, with ambitions to ascend to the second. "We are better off than our neighbors in South America, Argentina and Chile, whose presence on the continent is older and more visible," says Professor Rocha-Campos.
According to Ronald Buss de Souza from INPE, Brazil's time to create an Antarctic research institute, similar to that of several other countries with bases in the region, has passed. He also believes that the Navy leadership is Proantar's Achilles heel. "Developed countries have established private Antarctic research institutes that manage the stations and research vessels. In Brazil and other countries that have territorial interests in Antarctica, such as Chile and Argentina, the military runs the bases," he says. "The station chief has always been a Brazilian naval officer. A researcher working in Antarctica has to ask for permission to work outside the station. If it is not granted, nothing happens. The officer will only refuse if there is a reason but he can invent obstacles to avoid accompanying the researcher on an unpleasant task," he explains. He complains that Brazil has not yet understood Antarctica's importance. "Our research focuses on the influence of the Amazon Region on climate, but 60% of our territory is more susceptible to the influence of Antarctica," he says.
In the short term, the challenge is to ensure that the research studies are maintained while a new station is built. One way of supporting the research is to keep a Brazilian ship docked near the station during the summer. "The rent of a third ship is also being considered," says Rosalinda Montone. Another idea is to look for collaborations that might allow the use of other countries' stations. An international tender will define the form of the new station. It will most likely start with the design of the Spanish Juan Carlos station, which has no adjacent modules, which keeps fire from spreading. Navy commander Julio Soares de Moura Neto said that the project will take into account the suggestions of the researchers. "Research is the reason why we're on Antarctica. The participation of researchers is extremely welcome," said Moura Neto, according to Agência Brasil.

This work first appeared on Pesquisa FAPESP under a CC-BY-NC-ND 4.0 license. Read the original here.

ROSALINDA MONTONEThe Comandante Ferraz Station in December 2006: 60 modules formed a villageROSALINDA MONTONE The reconstruction of the Comandante Ferraz Station, the Brazilian research base in Antarctica, destroyed by a fire on the morning of February 25, will only begin in two years' time and is expected to be complete by 2016. The tragedy, in which two soldiers died, was caused by a fire in power generators and had at least one immediate effect. It re-launched the debate about the Brazilian research ambitions on the frozen continent and the strategies necessary for the work to gain more relevance. The scientists agree that the station should be rebuilt in such a way as to increase safety and guarantee special support for the researchers. Until now, the complex and costly supply logistics and staff transport in the hands of the Navy often left the scientific goals in second place. There is also a common understanding that the financing model for research in Antarctica, based on public notices of the National Scientific and Technological Development Council (CNPq), which sponsor projects for a two-year term, calls for improvement. It needs to guarantee resources for long-term projects, especially for programs concerned with climate change data. Although not broadly know, Antarctica's influence on Brazil's climate is comparable with that of the Amazon. "Climate change is a major research topic in Antarctica involving areas such as glaciology, meteorology and biology," said Antonio Carlos Rocha-Campos, a retired professor from the Biosciences and Geosciences Institute at USP and the university's Antarctica Research Center coordinator. With a 13.6 million square kilometer area that is almost entirely covered by glaciers, Antarctica is the highest, coldest and driest continent, and it experiences the strongest winds on the planet. Jefferson Cardia Simões, a glaciologist, a Federal University of Rio Grande do Sul (UFRGS) professor and the first Brazilian to reach the South Pole by land in a scientific expedition in 2004, believes that a new research management model is also desirable in Antarctica. "It isn't a question of merely having a new station, but rather of rebuilding it with a certain aspects in mind" says Simões, and he mentions a few: cooperation with other countries, allowing cost sharing and raising research quality, expedition camp support in other regions, and making the researchers' work more rational. "The scientific community needs to make decisions about station management and about research on Antarctica. Today, logistics, operated by the Navy, and science, in the hand of the researchers, compete with one another. On a daily basis, priorities get lost because of too much demand," the researcher says. The number of Brazilians involved in research on Antarctica has grown. Therefore, the pressure to spend entire seasons on the continent, with all the associated costs and logistics, has grown stronger. "It's impossible for everyone to go out into the field every year. There's a time to collect data and another one to analyze it. And there's research that can be done without going to Antarctica, merely using data collected there" says the glaciologist. Historically, the bottleneck of the Brazilian Antarctic Program (Proantar) used to be the possibility to visit the station. ARMANDO HADANO/INPEUSP researchers collect data close to the station: 40% of the research projects were affectedARMANDO HADANO/INPE There are some 250 Brazilian researchers currently involved in studying this frozen continent. The station has the capacity to accommodate about 20% of this number. It is not always possible to enjoy the full potential on the base. In 2009, the Navy incorporated a polar ship, Almirante Maximiano, for its work in the region. However, in 2011, she practically worked on her own as Ary Rongel, the oceanographic ship supporting the station, had been damaged. Those who do manage to secure a spot on the station also face uncertainties . "I've already spent an entire week without being able to go out due to weather conditions, unfavorable for data collection" says Rosalinda Montone, the USP Oceanographic Institute's professor whose group lost a significant portion of their data about organic pollutants in marine environment to the fire this summer. "We will only be able to recover a small part of it," she says. A place on the ship and in the station The chance to travel on two Navy ships and spend a season in the station is usually reserved for projects included in CNPq's periodic announcements and, more recently, in the two National Science and Technology Institutes (INCT) dedicated to Antarctic research. One of the latter focuses on the role that the mass of ice has on the local climate and studies the fluctuation of the Antarctic climate and its influence on Brazil. The other focuses on the impact of human activity on the Antarctic environment. "The selection of projects is very strict and we have moved towards creating networks instead of stimulating the work of individual researchers," says Jefferson Simões. There is a recurring complaint about lack of investment in long-term projects. "The fact that one of the National Institute for Space Research (INPE) groups was not selected in CNPq's final announcement meant that we had to interrupt a set of meteorological data from the station as there was no one to collect it " says Ronald Buss de Souza, oceanographer and head of INPE's Antarctic program. Ilana Wainer, a professor at USP's Oceanographic Institute, emphasizes the importance of funding data collection that will benefit groups looking for information about the continent without necessarily going there every summer. "We've never been as well financed as now, but it takes more than two-year projects to ensure the monitoring of climate variables. It would be important to have continuous funding," said Ilana, whose work on modeling the Antarctic climate depends to a large extent on Southern Ocean data and on the variation in the area of sea ice. She is greatly dependent on the availability of two Navy ships, which are important for collecting data about the ocean. The station fire and the use of ships for logistics is likely to compromise one of Ilana's projects, Paleoantar, which expected to obtain ice samples to try to understand the so-called defrost pulsation, a possible trigger for climate variations. She says, however, that Brazil does not need to invest alone and mentions the Southern Ocean Observing System (Soos). This newly created, multidisciplinary network aims to conduct Southern Ocean observations to supply data on climate change, rising sea levels and the impact of global warming on marine ecosystems for various research lines. "Just one country can't do it," she says. She reminds us that studies on climate processes on a local scale are on the edge of a breakthrough and that computer models are having a difficulty simulating the interaction between the climate on Antarctica and the Southern hemisphere. In one example of research that can benefit these models, Ilana's team, in cooperation with researchers from Rio de Janeiro and France, came to the conclusion that the expansion of the hole in the ozone layer over Antarctica in the 1980s led to a wind regime change on the frozen continent with an impact on sea surface temperature in Bahia. "We found a cause and effect relationship between the decline of corals and the growth of the ozone hole. The hole increased the temperature difference between the Antarctic and the tropics intensifying the wind and there was a decrease in the growth of corals in Bahia. Although the gap has diminished, it is not clear if the coral situation has improved. The effects of global warming may have compensated, despite the winds returning to normal. " Over the past two years, USP's Rocha-Campos also called for international cooperation to carry out his research. He is counting on the backup from an Argentine base and benefitting from the cooperation with the Argentine Antarctic Institute. "We've already collected rock samples on King George Island, not far from the Brazilian station, on other occasions. For the research to move forward, we need to visit other places," says the professor. A group of researchers under his lead has recently identified a glacial structure essential to clarify the paleoclimatic history of Antarctica during the Miocene (about 15 million years ago). The structure, called a glacial clasts pavement , proves that there has been a period of expansion of the West Antarctic ice cap. Rocha-Campos and other Brazilian researchers are in favor of obtaining funds so that Brazil can participate in the program Antarctic Drilling (ANDRILL), an international consortium that has been carrying out geological surveys in the Antarctic continental coast. "If we manage to raise funds to participate, we will enter the mainstream of geological research in Antarctica," he says. Situated in the hottest part of the Antarctic continent, on King George Island, the Comandante Ferraz station guaranteed easy access for the two Brazilian ships. Several other countries have set up base in the region for a reason. It is in an open bay with broad beaches, which favors logistics and reduces costs. At the same time, it was able to support restricted sets of research studies, such as, for example, those in the field of marine biology, which were affected by most by the fire. Comprising over 60 interconnected modules, it grew over time into a village on the coast. In the winter, only a smaller number of researchers remained at the base. During the cold season, access was not possible by ship, as these vessels only go to the continent between October and April, so the base was visited by the airplanes of the Brazilian Air Force (FAB). "The location is also ideal due to its proximity to two lakes – sources of fresh water," says Rosalinda Montone from USP, who has been to Antarctica 17 times. FABIO MELO FONTESThe inauguration of the Brazilian Station in 1984: researchers travelled at the Navy's invitationFABIO MELO FONTES The tragedy interrupted 40% of Brazilian research in Antarctica – a sign that the country's scientific presence on the continent was not exclusively dependent on the logistics structure managed by the Navy. On the one hand, data collection modules located between 300 meters and one kilometer from the burnt base were spared. On the other, there has been a steady increase in the research carried out off the base. Jefferson Cardia Simões' expedition to the geographic South Pole in late 2004, where he collected ice testimonies (cylinders), depended on a logistics schedule outside of what the Navy offered – involving flights by Chilean airplanes and renting a polar tractor together with other researchers. In January, a team led by Heitor Evangelista from the State University of Rio de Janeiro (UERJ) and Jefferson Simões installed Cristofera I – the first Brazilian scientific module obtaining weather data inside the Antarctic continent, located 2.5 thousand kilometers to the south of the station. The 1982 expedition The history of Brazilian research funding in Antarctica has several phases. In 1975, Brazil signed the Antarctic Treaty, which dedicated the continent to peaceful activities, in particular scientific research. The country conducted its first expedition in 1982. At the advent of Proantar in 1984 and the inauguration of the Comandante Ferraz station, it was the Navy itself who called for researchers to work in the region through the Inter-ministerial Commission for Sea Resources (CIRM). "The research program was ordered by CIRM, which invited selected institutions and sought to lead research in certain areas," says Ronald Buss de Souza. It is was back then that institutions such as Inpe and the Oceanographic and Earth Sciences Institutes at USP were incorporated into the research effort. USP's oceanographic ship, Captain W. Besnard, made six trips to Antarctica in the 1980s aiding the researchers along with the Navy's Baron de Tefé. Proantar's second phase began in 1991when the Navy decided to withdraw from research and only take on the logistics of trips to the base. CNPq took over the research. "There was already a critical mass to compete in announcements and CNPq began evaluating projects according to scientific productivity," said Souza. It was not an easy time. "The bride was beautiful but it came without a dowry," says Professor Rocha-Campos. CNPq's resources were limited so that the Ministry of Environment's involvement in Proantar brought relief in a third phase of Antarctic research funding. As determined in a protocol signed by Brazil, the research started to be monitored to reduce its environmental impact. In the most recent, fourth stage, CNPq released bids to select projects and two National Institutes of Science and Technology were created. The latter work as virtual networks of excellence and are maintained by CNPq and by state foundations that support research. New research groups, mainly from Rio Grande do Sul, were formed over time. "Unlike what happened in the 1980s, when scientists made concessions in their research to include Antarctica, we now have a generation of scientists dedicated to research on the continent. This critical mass pushed for more resources and opportunity to conduct their studies," says Jefferson Simões. MARIA ROSA PEDREIRO/UFPRThe station in flames: two casualties and reconstruction forecast to be ready in 2016MARIA ROSA PEDREIRO/UFPR The United States, Britain, Japan and Germany invest the most in research about the Antarctic. "They are the first line of research with stations in different parts of Antarctica and icebreakers capable of reaching them," says Jefferson Simões. China and India rank second, as they have multiplied their investments in the region recently, in addition to France, Norway and Russia. Brazil, with its increase in research groups in recent years, would be in the third platoon, with ambitions to ascend to the second. "We are better off than our neighbors in South America, Argentina and Chile, whose presence on the continent is older and more visible," says Professor Rocha-Campos. According to Ronald Buss de Souza from INPE, Brazil's time to create an Antarctic research institute, similar to that of several other countries with bases in the region, has passed. He also believes that the Navy leadership is Proantar's Achilles heel. "Developed countries have established private Antarctic research institutes that manage the stations and research vessels. In Brazil and other countries that have territorial interests in Antarctica, such as Chile and Argentina, the military runs the bases," he says. "The station chief has always been a Brazilian naval officer. A researcher working in Antarctica has to ask for permission to work outside the station. If it is not granted, nothing happens. The officer will only refuse if there is a reason but he can invent obstacles to avoid accompanying the researcher on an unpleasant task," he explains. He complains that Brazil has not yet understood Antarctica's importance. "Our research focuses on the influence of the Amazon Region on climate, but 60% of our territory is more susceptible to the influence of Antarctica," he says. In the short term, the challenge is to ensure that the research studies are maintained while a new station is built. One way of supporting the research is to keep a Brazilian ship docked near the station during the summer. "The rent of a third ship is also being considered," says Rosalinda Montone. Another idea is to look for collaborations that might allow the use of other countries' stations. An international tender will define the form of the new station. It will most likely start with the design of the Spanish Juan Carlos station, which has no adjacent modules, which keeps fire from spreading. Navy commander Julio Soares de Moura Neto said that the project will take into account the suggestions of the researchers. "Research is the reason why we're on Antarctica. The participation of researchers is extremely welcome," said Moura Neto, according to Agência Brasil.

redpajama_set_name: RedPajamaCommonCrawl


text:
Gallery: Rio de Janeiro police take part in World Cup security drills in shadow of Christ the Redeemer
Metro PicturesMonday 8 Apr 2013 11:06 am
Elite police forces in Rio de Janeiro have taken part in a series of security drills in preparation for a number of upcoming high profile events.
The Brazilian city is set to play host to football's Confederations Cup later this year, ahead of next year's World Cup.
Rio is also hosting World Youth Day in July, as well as the Olympics in 2016.
As part of the drills, bomb squad officers took part in a simulated terrorist attack on a subway station, while special operations officers trained at the feet of the statue of Christ the Redeemer.
Members of the Elite Unit of the Brazilian Military Police (BOPE) practice maneuvers in front of the Christ the Reedemer statue on Corcovado Hill in Rio de Janeiro, Brazil (Picture: AFP/Getty)
Members of the Elite Unit of the Brazilian Military Police (BOPE) practice…
Members of the Elite Unit of the Brazilian Military Police (BOPE) practice maneuvers in front of the Christ the Reedemer statue on Corcovado Hill in Rio de Janeiro (Picture: AFP/Getty)
A Rio police special unit CORE bomb squad agent takes part in a terrorist attack drill at a subway station in Rio de Janeiro (Picture: AFP/Getty)
A Rio police special unit CORE bomb squad agent takes part in a terrorist…
Rio's police special unit CORE agents take part in a terrorist attack drill at a subway station in Rio de Janeiro (Picture: AFP/Getty)
Rio's police special unit CORE agents take part in a terrorist attack drill at…
Members of the Elite Unit of the Brazilian Military Police (BOPE) practice maneuvers on Corcovado Hill in Rio de Janeiro (Picture: AFP/Getty)
A Brazilian national force agent inspects bags with a drug-sniffing dog at a border control check point along the border with Bolivia, in Corumba, a municipality in the Brazilian state of Mato Grosso do Sul (Picture: AFP/Getty)
A Brazilian national force agent inspects bags with a drug-sniffing dog at a…
Brazilian federal police agents patrol the Paraguay river, in Corumba, a municipality in the Brazilian state of Mato Grosso do Sul, along the border with Bolivia (Picture: AFP/Getty)
Brazilian federal police agents patrol the Paraguay river, in Corumba, a…
The Elite Unit of the Brazilian Military Police (BOPE) practices maneuvers on Corcovado Hill overlooking Rio de Janeiro (Picture: AFP/Getty)
The Elite Unit of the Brazilian Military Police (BOPE) practices maneuvers on…
For more News galleries click here
News galleryRio De JaneiroWorld Cup
Killers 'filmed themselves beheading teenager to deliver as a warning'
Pedophile who molested baby freed from jail after transitioning to become a woman
'Domestic abuser poured bleach in baby's eyes while attacking her mother'
Home › News › World


Carlsbad semiconductor outfit MaxLinear said this week that it is buying an in-home broadband product line from publicly traded Marvell Technology for $21 million in cash.
The move further diversities MaxLinear's radio frequency and mix-signal chip business into new markets – specifically for distributing broadband throughout non-cable homes.
MaxLinear announced the deal as part of its fourth quarter and year-end earnings conference call. Chief Executive Kishore Seendripu said the purchase complements the company's current whole-home DVR technology for cable households, which are more prevalent in the U.S. and some parts of Europe than elsewhere worldwide.
The company's current cable technology allows subscribers to stream movies and shows recorded on a DVR in the living room to other TVs throughout the home over coaxial cable lines. It also helps cover W-Fi dead spots through extender boxes plugged into cable outlets.
The Marvell technology, called G.hn, does the same thing but over in-home electrical or telephone lines.
Seendripu said G.hn technology expands the company's addressable market by roughly 200 million non-cable broadband subscriber homes globally.
There is still some work to do. MaxLinear doesn't expect the acquisition to add to earnings this year.
MaxLinear develops radio frequency and mixed signal semiconductors for broadband networks. But it also has expanded recently into new markets via acquisitions, including the purchase of Broadcom's wireless backhaul business division and Microsemi's cellular base station RF transceiver arm.
For its fiscal fourth quarter, MaxLinear posted sales of $87.1 million, down from $99 million a year earlier as the product life cycles wind down for some of MaxLinear's older set-up box chips.
Net income was $8.3 million, or 12 cents a share, compared with a loss of $8.5 million the same quarter of 2015. The results were in line with analysts' expectations.
For the full year, MaxLinear saw revenue increase 29 percent to $388 million. Net income reached $61 million, or 91 cents a share, compared with a loss of $42 million the prior year.
MaxLinear's shares ended the week up slightly at $27.35 on the New York Stock Exchange.


text:
package org.wildfly.camel.test.classloading;

import org.apache.camel.CamelContext;
import org.apache.camel.ServiceStatus;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.camel.test.classloading.subC.XmlRouteBuilder;
import org.wildfly.extension.camel.CamelContextRegistry;

@RunWith(Arquillian.class)
public class CamelEnablementImportResourceInWarTest {

    @ArquillianResource
    CamelContextRegistry contextRegistry;

    @Deployment
    public static WebArchive createDeployment() {
        WebArchive war = ShrinkWrap.create(WebArchive.class, "camel-import-resource-tests.war")
            .addClass(XmlRouteBuilder.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsResource("classloading/spring-camel-context.xml");
        return war;
    }

    @Test
    public void testCamelEnabled() throws Exception {
        CamelContext camelctx = contextRegistry.getCamelContext("classloading-spring-context");
        Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    }
}

redpajama_set_name: RedPajamaGithub


text:
Q: Code copied and pasted from outside sources into Visual Studio Code not working I have come across this recent problem when I copy & paste code from outside sources -- for example, GitHub sources or from my own Google Docs -- and paste it into a file within my Visual Studio Code. When the code is pasted into my VSC, it doesn't work right away. I've found that I have to comment out the code, then retype the entire code manually for it to work.
Is there a recent virus running around in VSC? Or do I have some extension or component in VSC I don't know about which is blocking this ability to allow copied and pasted code to work?

redpajama_set_name: RedPajamaStackExchange