{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE GeneralizedNewtypeDeriving #-}{-# LANGUAGE NoImplicitPrelude #-}{-# LANGUAGE PolyKinds #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE Trustworthy #-}------------------------------------------------------------------------------- |-- Module : Data.Functor.Const-- Copyright : Conor McBride and Ross Paterson 2005-- License : BSD-style (see the LICENSE file in the distribution)---- Maintainer : libraries@haskell.org-- Stability : experimental-- Portability : portable-- The 'Const' functor.---- @since 4.9.0.0moduleData.Functor.Const(Const (..))whereimportData.Bits (Bits ,FiniteBits )importData.Foldable (Foldable (foldMap ))importForeign.Storable (Storable )importGHC.Arr (Ix )importGHC.Base importGHC.Enum (Bounded ,Enum )importGHC.Float (Floating ,RealFloat )importGHC.Generics (Generic ,Generic1 )importGHC.Num (Num )importGHC.Real (Fractional ,Integral ,Real ,RealFrac )importGHC.Read (Read (readsPrec ),readParen ,lex )importGHC.Show (Show (showsPrec ),showParen ,showString )-- | The 'Const' functor.newtypeConst a b =Const {getConst ::a }deriving(Bits ,Bounded ,Enum ,Eq,FiniteBits ,Floating ,Fractional ,Generic ,Generic1 ,Integral ,Ix ,Monoid ,Num ,Ord,Real ,RealFrac ,RealFloat ,Storable )-- | This instance would be equivalent to the derived instances of the-- 'Const' newtype if the 'runConst' field were removedinstanceRead a =>Read (Const a b )wherereadsPrec d =readParen (d >10)$ \r ->[(Const x ,t )|("Const",s )<-lex r ,(x ,t )<-readsPrec 11s ]-- | This instance would be equivalent to the derived instances of the-- 'Const' newtype if the 'runConst' field were removedinstanceShow a =>Show (Const a b )whereshowsPrec d (Const x )=showParen (d >10)$ showString "Const ". showsPrec 11x instanceFoldable (Const m )wherefoldMap __=mempty instanceFunctor (Const m )wherefmap _(Const v )=Const v instanceMonoid m =>Applicative (Const m )wherepure _=Const mempty (<*> )=coerce(mappend ::m ->m ->m )-- This is pretty much the same as-- Const f <*> Const v = Const (f `mappend` v)-- but guarantees that mappend for Const a b will have the same arity-- as the one for a; it won't create a closure to raise the arity-- to 2.

AltStyle によって変換されたページ (->オリジナル) /