Friday, March 30, 2007

Eq but not Ord

I recently wondered, which data types in the Haskell library have instances for Eq, but not for Ord? Of course, everything with Ord is obligated to provide Eq, but how many provide only Eq?

The answer is 82:

Action, Body, BuildInfo, Callconv, Clause, Compiler, CompilerFlavor, Con, ConfigFlags, Constr, ConstrRep, Counts, DataRep, Dec, Errno, Exception, Executable, Exp, Extension, Fixity, FixityDirection, Foreign, FunDep, Guard, Handle, HandlePosn, HsAlt, HsAssoc, HsBangType, HsConDecl, HsDecl, HsExp, HsExportSpec, HsFieldUpdate, HsGuardedAlt, HsGuardedAlts, HsGuardedRhs, HsImportDecl, HsImportSpec, HsLiteral, HsMatch, HsPat, HsPatField, HsQualType, HsRhs, HsStmt, HsType, IOArray, IOErrorType, IOException, IORef, Lexeme, Library, License, Lit, LocalBuildInfo, Match, MVar, Node, Orient, PackageDescription, PackageIdentifier, Pat, Range, Safety, SockAddr, Socket, SocketStatus, StableName, StablePtr, STArray, State, Stmt, STRef, Strict, Tree, TVar, TyCon, Type, TypeRep, URI, URIAuth

2 comments:

Bryan Burgers said...

Out of curiosity, how did you find them? Did you use the YHC or GHC API somehow? Can you post the code? I'm just being curious, here.

Neil Mitchell said...

No code involved, just the Hoogle database [http://www.haskell.org/hoogle/res/hoogle.txt] and some regular expressions in TextPad. The basic sequence of regular expressions was:

remove the instance bits
remove the bit before the context =>
split into Eq and Ord sections (sorting)
Tag Eq and Ord at the begining and end of each line
Sort by the middle column (names)
Search for Eq\nEq

I'm sure you could have done it with a bit of code, but in this particular case it wasn't too hard to do it manually.