Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude, MagicHash, StandaloneDeriving #-}{-# OPTIONS_GHC -fno-warn-unused-imports #-}-- XXX -fno-warn-unused-imports needed for the GHC.Tuple import below. Sigh.{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------- |-- Module      :  GHC.Classes-- Copyright   :  (c) The University of Glasgow, 1992-2002-- License     :  see libraries/base/LICENSE---- Maintainer  :  cvs-ghc@haskell.org-- Stability   :  internal-- Portability :  non-portable (GHC extensions)---- Basic classes.-------------------------------------------------------------------------------moduleGHC.ClasseswhereimportGHC.Integer-- GHC.Magic is used in some derived instancesimportGHC.Magic()importGHC.OrderingimportGHC.PrimimportGHC.TupleimportGHC.TypesimportGHC.Unit-- For defining instances for the generic deriving mechanismimportGHC.Generics(Arity(..),Associativity(..),Fixity(..))infix4==,/=,<,<=,>=,>infixr3&&infixr2||default()-- Double isn't available yet-- | The 'Eq' class defines equality ('==') and inequality ('/=').-- All the basic datatypes exported by the "Prelude" are instances of 'Eq',-- and 'Eq' may be derived for any datatype whose constituents are also-- instances of 'Eq'.---- Minimal complete definition: either '==' or '/='.--classEqawhere(==),(/=)::a->a->Bool{-# INLINE (/=) #-}{-# INLINE (==) #-}x/=y=not(x==y)x==y=not(x/=y)derivinginstanceEq()derivinginstance(Eqa,Eqb)=>Eq(a,b)derivinginstance(Eqa,Eqb,Eqc)=>Eq(a,b,c)derivinginstance(Eqa,Eqb,Eqc,Eqd)=>Eq(a,b,c,d)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe)=>Eq(a,b,c,d,e)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf)=>Eq(a,b,c,d,e,f)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg)=>Eq(a,b,c,d,e,f,g)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh)=>Eq(a,b,c,d,e,f,g,h)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh,Eqi)=>Eq(a,b,c,d,e,f,g,h,i)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh,Eqi,Eqj)=>Eq(a,b,c,d,e,f,g,h,i,j)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh,Eqi,Eqj,Eqk)=>Eq(a,b,c,d,e,f,g,h,i,j,k)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh,Eqi,Eqj,Eqk,Eql)=>Eq(a,b,c,d,e,f,g,h,i,j,k,l)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh,Eqi,Eqj,Eqk,Eql,Eqm)=>Eq(a,b,c,d,e,f,g,h,i,j,k,l,m)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh,Eqi,Eqj,Eqk,Eql,Eqm,Eqn)=>Eq(a,b,c,d,e,f,g,h,i,j,k,l,m,n)derivinginstance(Eqa,Eqb,Eqc,Eqd,Eqe,Eqf,Eqg,Eqh,Eqi,Eqj,Eqk,Eql,Eqm,Eqn,Eqo)=>Eq(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)instance(Eqa)=>Eq[a]where{-# SPECIALISE instance Eq [Char] #-}[]==[]=True(x:xs)==(y:ys)=x==y&&xs==ys_xs==_ys=FalsederivinginstanceEqBoolderivinginstanceEqOrderinginstanceEqCharwhere(C#c1)==(C#c2)=c1`eqChar#`c2(C#c1)/=(C#c2)=c1`neChar#`c2instanceEqIntegerwhere(==)=eqInteger(/=)=neqIntegerinstanceEqFloatwhere(F#x)==(F#y)=x`eqFloat#`yinstanceEqDoublewhere(D#x)==(D#y)=x==##yinstanceEqIntwhere(==)=eqInt(/=)=neInt{-# INLINE eqInt #-}{-# INLINE neInt #-}eqInt,neInt::Int->Int->Bool(I#x)`eqInt`(I#y)=x==#y(I#x)`neInt`(I#y)=x/=#y-- | The 'Ord' class is used for totally ordered datatypes.---- Instances of 'Ord' can be derived for any user-defined-- datatype whose constituent types are in 'Ord'.  The declared order-- of the constructors in the data declaration determines the ordering-- in derived 'Ord' instances.  The 'Ordering' datatype allows a single-- comparison to determine the precise ordering of two objects.---- Minimal complete definition: either 'compare' or '<='.-- Using 'compare' can be more efficient for complex types.--class(Eqa)=>Ordawherecompare::a->a->Ordering(<),(<=),(>),(>=)::a->a->Boolmax,min::a->a->acomparexy=ifx==ythenEQ-- NB: must be '<=' not '<' to validate the-- above claim about the minimal things that-- can be defined for an instance of Ord:elseifx<=ythenLTelseGTx<y=casecomparexyof{LT->True;_->False}x<=y=casecomparexyof{GT->False;_->True}x>y=casecomparexyof{GT->True;_->False}x>=y=casecomparexyof{LT->False;_->True}-- These two default methods use '<=' rather than 'compare'-- because the latter is often more expensivemaxxy=ifx<=ythenyelsexminxy=ifx<=ythenxelseyderivinginstanceOrd()derivinginstance(Orda,Ordb)=>Ord(a,b)derivinginstance(Orda,Ordb,Ordc)=>Ord(a,b,c)derivinginstance(Orda,Ordb,Ordc,Ordd)=>Ord(a,b,c,d)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde)=>Ord(a,b,c,d,e)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf)=>Ord(a,b,c,d,e,f)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg)=>Ord(a,b,c,d,e,f,g)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh)=>Ord(a,b,c,d,e,f,g,h)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh,Ordi)=>Ord(a,b,c,d,e,f,g,h,i)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh,Ordi,Ordj)=>Ord(a,b,c,d,e,f,g,h,i,j)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh,Ordi,Ordj,Ordk)=>Ord(a,b,c,d,e,f,g,h,i,j,k)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh,Ordi,Ordj,Ordk,Ordl)=>Ord(a,b,c,d,e,f,g,h,i,j,k,l)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh,Ordi,Ordj,Ordk,Ordl,Ordm)=>Ord(a,b,c,d,e,f,g,h,i,j,k,l,m)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh,Ordi,Ordj,Ordk,Ordl,Ordm,Ordn)=>Ord(a,b,c,d,e,f,g,h,i,j,k,l,m,n)derivinginstance(Orda,Ordb,Ordc,Ordd,Orde,Ordf,Ordg,Ordh,Ordi,Ordj,Ordk,Ordl,Ordm,Ordn,Ordo)=>Ord(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)instance(Orda)=>Ord[a]where{-# SPECIALISE instance Ord [Char] #-}compare[][]=EQcompare[](_:_)=LTcompare(_:_)[]=GTcompare(x:xs)(y:ys)=casecomparexyofEQ->comparexsysother->otherderivinginstanceOrdBoolderivinginstanceOrdOrdering-- We don't use deriving for Ord Char, because for Ord the derived-- instance defines only compare, which takes two primops.  Then-- '>' uses compare, and therefore takes two primops instead of one.instanceOrdCharwhere(C#c1)>(C#c2)=c1`gtChar#`c2(C#c1)>=(C#c2)=c1`geChar#`c2(C#c1)<=(C#c2)=c1`leChar#`c2(C#c1)<(C#c2)=c1`ltChar#`c2instanceOrdIntegerwhere(<=)=leInteger(>)=gtInteger(<)=ltInteger(>=)=geIntegercompare=compareIntegerinstanceOrdFloatwhere(F#x)`compare`(F#y)=ifx`ltFloat#`ythenLTelseifx`eqFloat#`ythenEQelseGT(F#x)<(F#y)=x`ltFloat#`y(F#x)<=(F#y)=x`leFloat#`y(F#x)>=(F#y)=x`geFloat#`y(F#x)>(F#y)=x`gtFloat#`yinstanceOrdDoublewhere(D#x)`compare`(D#y)=ifx<##ythenLTelseifx==##ythenEQelseGT(D#x)<(D#y)=x<##y(D#x)<=(D#y)=x<=##y(D#x)>=(D#y)=x>=##y(D#x)>(D#y)=x>##yinstanceOrdIntwherecompare=compareInt(<)=ltInt(<=)=leInt(>=)=geInt(>)=gtInt{-# INLINE gtInt #-}{-# INLINE geInt #-}{-# INLINE ltInt #-}{-# INLINE leInt #-}gtInt,geInt,ltInt,leInt::Int->Int->Bool(I#x)`gtInt`(I#y)=x>#y(I#x)`geInt`(I#y)=x>=#y(I#x)`ltInt`(I#y)=x<#y(I#x)`leInt`(I#y)=x<=#ycompareInt::Int->Int->Ordering(I#x#)`compareInt`(I#y#)=compareInt#x#y#compareInt#::Int#->Int#->OrderingcompareInt#x#y#|x#<#y#=LT|x#==#y#=EQ|True=GT-- OK, so they're technically not part of a class...:-- Boolean functions-- | Boolean \"and\"(&&)::Bool->Bool->BoolTrue&&x=xFalse&&_=False-- | Boolean \"or\"(||)::Bool->Bool->BoolTrue||_=TrueFalse||x=x-- | Boolean \"not\"not::Bool->BoolnotTrue=FalsenotFalse=True-------------------------------------------------------------------------- Generic deriving-------------------------------------------------------------------------- We need instances for some basic datatypes, but some of those use Int,-- so we have to put the instances herederivinginstanceEqArityderivinginstanceEqAssociativityderivinginstanceEqFixityderivinginstanceOrdArityderivinginstanceOrdAssociativityderivinginstanceOrdFixity

[8]ページ先頭

©2009-2025 Movatter.jp