Wolfgang Jeltsch pushed to branch wip/jeltsch/text-read-implementation-into-base at Glasgow Haskell Compiler / GHC
Commits:
-
f77ff5a5
by Wolfgang Jeltsch at 2026-04-14T21:07:56+03:00
-
d48a6e49
by Wolfgang Jeltsch at 2026-04-14T21:08:17+03:00
-
42b80acd
by Wolfgang Jeltsch at 2026-04-14T21:09:55+03:00
15 changed files:
- libraries/base/src/Data/Data.hs
- libraries/base/src/Data/Functor/Classes.hs
- libraries/base/src/Data/Functor/Compose.hs
- libraries/base/src/Data/Version.hs
- libraries/base/src/Prelude.hs
- libraries/base/src/Text/Read.hs
- libraries/ghc-internal/ghc-internal.cabal.in
- libraries/ghc-internal/src/GHC/Internal/Data/Data.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Version.hs
- − libraries/ghc-internal/src/GHC/Internal/Text/Read.hs
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/interface-stability/base-exports.stdout-ws-32
- testsuite/tests/plugins/plugins10.stdout
Changes:
| ... | ... | @@ -99,3 +99,38 @@ module Data.Data ( |
| 99 | 99 | |
| 100 | 100 | import GHC.Internal.Data.Data
|
| 101 | 101 | import Data.Typeable
|
| 102 | + |
|
| 103 | +import GHC.Real (toRational)
|
|
| 104 | +import GHC.Float (Double)
|
|
| 105 | +import Data.Eq ((==))
|
|
| 106 | +import Data.Function ((.))
|
|
| 107 | +import Data.Maybe (Maybe (Nothing, Just))
|
|
| 108 | +import Data.List (filter)
|
|
| 109 | +import Data.String (String)
|
|
| 110 | +import Text.Read (Read, reads)
|
|
| 111 | + |
|
| 112 | +-- | Lookup a constructor via a string
|
|
| 113 | +readConstr :: DataType -> String -> Maybe Constr
|
|
| 114 | +readConstr dt str =
|
|
| 115 | + case dataTypeRep dt of
|
|
| 116 | + AlgRep cons -> idx cons
|
|
| 117 | + IntRep -> mkReadCon (\i -> (mkPrimCon dt str (IntConstr i)))
|
|
| 118 | + FloatRep -> mkReadCon ffloat
|
|
| 119 | + CharRep -> mkReadCon (\c -> (mkPrimCon dt str (CharConstr c)))
|
|
| 120 | + NoRep -> Nothing
|
|
| 121 | + where
|
|
| 122 | + |
|
| 123 | + -- Read a value and build a constructor
|
|
| 124 | + mkReadCon :: Read t => (t -> Constr) -> Maybe Constr
|
|
| 125 | + mkReadCon f = case (reads str) of
|
|
| 126 | + [(t,"")] -> Just (f t)
|
|
| 127 | + _ -> Nothing
|
|
| 128 | + |
|
| 129 | + -- Traverse list of algebraic datatype constructors
|
|
| 130 | + idx :: [Constr] -> Maybe Constr
|
|
| 131 | + idx cons = case filter ((==) str . showConstr) cons of
|
|
| 132 | + [] -> Nothing
|
|
| 133 | + hd : _ -> Just hd
|
|
| 134 | + |
|
| 135 | + ffloat :: Double -> Constr
|
|
| 136 | + ffloat = mkPrimCon dt str . FloatConstr . toRational |
| ... | ... | @@ -85,7 +85,7 @@ import GHC.Internal.Read (expectP, list, paren, readField) |
| 85 | 85 | import GHC.Internal.Show (appPrec)
|
| 86 | 86 | |
| 87 | 87 | import GHC.Internal.Text.ParserCombinators.ReadPrec (ReadPrec, readPrec_to_S, readS_to_Prec, pfail)
|
| 88 | -import GHC.Internal.Text.Read (Read(..), parens, prec, step, reset)
|
|
| 88 | +import Text.Read (Read(..), parens, prec, step, reset)
|
|
| 89 | 89 | import GHC.Internal.Text.Read.Lex (Lexeme(..))
|
| 90 | 90 | import GHC.Internal.Text.Show (showListWith)
|
| 91 | 91 | import Prelude
|
| ... | ... | @@ -35,7 +35,7 @@ import GHC.Internal.Data.Foldable (Foldable(..)) |
| 35 | 35 | import GHC.Internal.Data.Monoid (Sum(..), All(..), Any(..), Product(..))
|
| 36 | 36 | import GHC.Internal.Data.Type.Equality (TestEquality(..), (:~:)(..))
|
| 37 | 37 | import GHC.Generics (Generic, Generic1)
|
| 38 | -import GHC.Internal.Text.Read (Read(..), ReadPrec, readListDefault, readListPrecDefault)
|
|
| 38 | +import Text.Read (Read(..), ReadPrec, readListDefault, readListPrecDefault)
|
|
| 39 | 39 | import Prelude
|
| 40 | 40 | |
| 41 | 41 | infixr 9 `Compose`
|
| 1 | 1 | {-# LANGUAGE Safe #-}
|
| 2 | 2 | |
| 3 | +{-# LANGUAGE StandaloneDeriving #-}
|
|
| 4 | + |
|
| 5 | +{-# OPTIONS_GHC -Wno-orphans #-}
|
|
| 6 | + |
|
| 3 | 7 | -- |
|
| 4 | 8 | -- Module : Data.Version
|
| 5 | 9 | -- Copyright : (c) The University of Glasgow 2004
|
| ... | ... | @@ -33,3 +37,25 @@ module Data.Version ( |
| 33 | 37 | ) where
|
| 34 | 38 | |
| 35 | 39 | import GHC.Internal.Data.Version
|
| 40 | + |
|
| 41 | +import Control.Applicative (pure, (*>))
|
|
| 42 | +import Data.Functor (fmap)
|
|
| 43 | +import Data.Char (isDigit, isAlphaNum)
|
|
| 44 | +import Text.ParserCombinators.ReadP (ReadP, char, munch1, sepBy1, many)
|
|
| 45 | +import Text.Read (Read, read)
|
|
| 46 | + |
|
| 47 | +{-NOTE:
|
|
| 48 | + The following instance is technically an orphan, but practically it is not,
|
|
| 49 | + since ordinary users should not use @ghc-internal@ directly and thus get
|
|
| 50 | + 'Version' only through this module.
|
|
| 51 | +-}
|
|
| 52 | + |
|
| 53 | +-- | @since base-2.01
|
|
| 54 | +deriving instance Read Version
|
|
| 55 | + |
|
| 56 | +-- | A parser for versions in the format produced by 'showVersion'.
|
|
| 57 | +--
|
|
| 58 | +parseVersion :: ReadP Version
|
|
| 59 | +parseVersion = do branch <- sepBy1 (fmap read (munch1 isDigit)) (char '.')
|
|
| 60 | + tags <- many (char '-' *> munch1 isAlphaNum)
|
|
| 61 | + pure (Version branch tags) |
| ... | ... | @@ -179,7 +179,7 @@ import GHC.Internal.Data.Tuple |
| 179 | 179 | import GHC.Internal.Base hiding ( foldr, mapM, sequence )
|
| 180 | 180 | import GHC.Internal.Classes
|
| 181 | 181 | import GHC.Internal.Err
|
| 182 | -import GHC.Internal.Text.Read
|
|
| 182 | +import Text.Read
|
|
| 183 | 183 | import GHC.Internal.Enum
|
| 184 | 184 | import GHC.Internal.Num
|
| 185 | 185 | import GHC.Internal.Prim (seq)
|
| ... | ... | @@ -39,5 +39,84 @@ module Text.Read |
| 39 | 39 | readMaybe
|
| 40 | 40 | ) where
|
| 41 | 41 | |
| 42 | -import GHC.Internal.Text.Read
|
|
| 42 | +import GHC.Err (errorWithoutStackTrace)
|
|
| 43 | +import GHC.Read
|
|
| 44 | + (
|
|
| 45 | + ReadS,
|
|
| 46 | + Read (readsPrec, readList, readPrec, readListPrec),
|
|
| 47 | + lex,
|
|
| 48 | + readParen,
|
|
| 49 | + readListDefault,
|
|
| 50 | + lexP,
|
|
| 51 | + parens,
|
|
| 52 | + readListPrecDefault
|
|
| 53 | + )
|
|
| 54 | +import Control.Monad (return)
|
|
| 55 | +import Data.Function (id)
|
|
| 56 | +import Data.Maybe (Maybe (Nothing, Just))
|
|
| 57 | +import Data.Either (Either (Left, Right), either)
|
|
| 58 | +import Data.String (String)
|
|
| 59 | +import Text.Read.Lex (Lexeme (Char, String, Punc, Ident, Symbol, Number, EOF))
|
|
| 60 | +import Text.ParserCombinators.ReadP (skipSpaces)
|
|
| 43 | 61 | import Text.ParserCombinators.ReadPrec
|
| 62 | + |
|
| 63 | +-- $setup
|
|
| 64 | +-- >>> import Prelude
|
|
| 65 | + |
|
| 66 | +------------------------------------------------------------------------
|
|
| 67 | +-- utility functions
|
|
| 68 | + |
|
| 69 | +-- | equivalent to 'readsPrec' with a precedence of 0.
|
|
| 70 | +reads :: Read a => ReadS a
|
|
| 71 | +reads = readsPrec minPrec
|
|
| 72 | + |
|
| 73 | +-- | Parse a string using the 'Read' instance.
|
|
| 74 | +-- Succeeds if there is exactly one valid result.
|
|
| 75 | +-- A 'Left' value indicates a parse error.
|
|
| 76 | +--
|
|
| 77 | +-- >>> readEither "123" :: Either String Int
|
|
| 78 | +-- Right 123
|
|
| 79 | +--
|
|
| 80 | +-- >>> readEither "hello" :: Either String Int
|
|
| 81 | +-- Left "Prelude.read: no parse"
|
|
| 82 | +--
|
|
| 83 | +-- @since base-4.6.0.0
|
|
| 84 | +readEither :: Read a => String -> Either String a
|
|
| 85 | +readEither s =
|
|
| 86 | + case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of
|
|
| 87 | + [x] -> Right x
|
|
| 88 | + [] -> Left "Prelude.read: no parse"
|
|
| 89 | + _ -> Left "Prelude.read: ambiguous parse"
|
|
| 90 | + where
|
|
| 91 | + read' =
|
|
| 92 | + do x <- readPrec
|
|
| 93 | + lift skipSpaces
|
|
| 94 | + return x
|
|
| 95 | + |
|
| 96 | +-- | Parse a string using the 'Read' instance.
|
|
| 97 | +-- Succeeds if there is exactly one valid result.
|
|
| 98 | +--
|
|
| 99 | +-- >>> readMaybe "123" :: Maybe Int
|
|
| 100 | +-- Just 123
|
|
| 101 | +--
|
|
| 102 | +-- >>> readMaybe "hello" :: Maybe Int
|
|
| 103 | +-- Nothing
|
|
| 104 | +--
|
|
| 105 | +-- @since base-4.6.0.0
|
|
| 106 | +readMaybe :: Read a => String -> Maybe a
|
|
| 107 | +readMaybe s = case readEither s of
|
|
| 108 | + Left _ -> Nothing
|
|
| 109 | + Right a -> Just a
|
|
| 110 | + |
|
| 111 | +-- | The 'read' function reads input from a string, which must be
|
|
| 112 | +-- completely consumed by the input process. 'read' fails with an 'error' if the
|
|
| 113 | +-- parse is unsuccessful, and it is therefore discouraged from being used in
|
|
| 114 | +-- real applications. Use 'readMaybe' or 'readEither' for safe alternatives.
|
|
| 115 | +--
|
|
| 116 | +-- >>> read "123" :: Int
|
|
| 117 | +-- 123
|
|
| 118 | +--
|
|
| 119 | +-- >>> read "hello" :: Int
|
|
| 120 | +-- *** Exception: Prelude.read: no parse
|
|
| 121 | +read :: Read a => String -> a
|
|
| 122 | +read s = either errorWithoutStackTrace id (readEither s) |
| ... | ... | @@ -329,7 +329,6 @@ Library |
| 329 | 329 | GHC.Internal.System.Posix.Types
|
| 330 | 330 | GHC.Internal.Text.ParserCombinators.ReadP
|
| 331 | 331 | GHC.Internal.Text.ParserCombinators.ReadPrec
|
| 332 | - GHC.Internal.Text.Read
|
|
| 333 | 332 | GHC.Internal.Text.Read.Lex
|
| 334 | 333 | GHC.Internal.Text.Show
|
| 335 | 334 | GHC.Internal.Type.Reflection
|
| ... | ... | @@ -61,6 +61,7 @@ module GHC.Internal.Data.Data ( |
| 61 | 61 | mkIntType,
|
| 62 | 62 | mkFloatType,
|
| 63 | 63 | mkCharType,
|
| 64 | + mkPrimCon,
|
|
| 64 | 65 | mkNoRepType,
|
| 65 | 66 | -- ** Observers
|
| 66 | 67 | dataTypeName,
|
| ... | ... | @@ -94,7 +95,6 @@ module GHC.Internal.Data.Data ( |
| 94 | 95 | constrIndex,
|
| 95 | 96 | -- ** From strings to constructors and vice versa: all data types
|
| 96 | 97 | showConstr,
|
| 97 | - readConstr,
|
|
| 98 | 98 | |
| 99 | 99 | -- * Convenience functions: take type constructors apart
|
| 100 | 100 | tyconUQname,
|
| ... | ... | @@ -126,10 +126,8 @@ import GHC.Internal.Base ( |
| 126 | 126 | import GHC.Internal.Err (errorWithoutStackTrace)
|
| 127 | 127 | import GHC.Internal.List
|
| 128 | 128 | import GHC.Internal.Num
|
| 129 | -import GHC.Internal.Read
|
|
| 130 | 129 | import GHC.Internal.Show
|
| 131 | 130 | import GHC.Internal.Tuple (Solo (..))
|
| 132 | -import GHC.Internal.Text.Read( reads )
|
|
| 133 | 131 | import GHC.Internal.Types (
|
| 134 | 132 | Bool(..), Char, Coercible, Float, Double, Type, type (~), type (~~),
|
| 135 | 133 | )
|
| ... | ... | @@ -688,32 +686,6 @@ showConstr :: Constr -> String |
| 688 | 686 | showConstr = constring
|
| 689 | 687 | |
| 690 | 688 | |
| 691 | --- | Lookup a constructor via a string
|
|
| 692 | -readConstr :: DataType -> String -> Maybe Constr
|
|
| 693 | -readConstr dt str =
|
|
| 694 | - case dataTypeRep dt of
|
|
| 695 | - AlgRep cons -> idx cons
|
|
| 696 | - IntRep -> mkReadCon (\i -> (mkPrimCon dt str (IntConstr i)))
|
|
| 697 | - FloatRep -> mkReadCon ffloat
|
|
| 698 | - CharRep -> mkReadCon (\c -> (mkPrimCon dt str (CharConstr c)))
|
|
| 699 | - NoRep -> Nothing
|
|
| 700 | - where
|
|
| 701 | - |
|
| 702 | - -- Read a value and build a constructor
|
|
| 703 | - mkReadCon :: Read t => (t -> Constr) -> Maybe Constr
|
|
| 704 | - mkReadCon f = case (reads str) of
|
|
| 705 | - [(t,"")] -> Just (f t)
|
|
| 706 | - _ -> Nothing
|
|
| 707 | - |
|
| 708 | - -- Traverse list of algebraic datatype constructors
|
|
| 709 | - idx :: [Constr] -> Maybe Constr
|
|
| 710 | - idx cons = case filter ((==) str . showConstr) cons of
|
|
| 711 | - [] -> Nothing
|
|
| 712 | - hd : _ -> Just hd
|
|
| 713 | - |
|
| 714 | - ffloat :: Double -> Constr
|
|
| 715 | - ffloat = mkPrimCon dt str . FloatConstr . toRational
|
|
| 716 | - |
|
| 717 | 689 | ------------------------------------------------------------------------------
|
| 718 | 690 | --
|
| 719 | 691 | -- Convenience functions: algebraic data types
|
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | --
|
| 11 | 11 | -- Maintainer : libraries@haskell.org
|
| 12 | 12 | -- Stability : stable
|
| 13 | --- Portability : non-portable (local universal quantification in ReadP)
|
|
| 13 | +-- Portability : non-portable
|
|
| 14 | 14 | --
|
| 15 | 15 | -- A general library for representation and manipulation of versions.
|
| 16 | 16 | --
|
| ... | ... | @@ -31,23 +31,17 @@ module GHC.Internal.Data.Version ( |
| 31 | 31 | -- * The @Version@ type
|
| 32 | 32 | Version(..),
|
| 33 | 33 | -- * A concrete representation of @Version@
|
| 34 | - showVersion, parseVersion,
|
|
| 34 | + showVersion,
|
|
| 35 | 35 | -- * Constructor function
|
| 36 | 36 | makeVersion
|
| 37 | 37 | ) where
|
| 38 | 38 | |
| 39 | -import GHC.Internal.Classes ( Eq(..), (&&) )
|
|
| 40 | -import GHC.Internal.Data.Functor ( Functor(..) )
|
|
| 39 | +import GHC.Internal.Classes ( Eq ((==)), (&&) )
|
|
| 41 | 40 | import GHC.Internal.Int ( Int )
|
| 42 | 41 | import GHC.Internal.Data.List ( map, sort, concat, concatMap, intersperse, (++) )
|
| 43 | 42 | import GHC.Internal.Data.Ord
|
| 44 | 43 | import GHC.Internal.Data.String ( String )
|
| 45 | -import GHC.Internal.Base ( Applicative(..) )
|
|
| 46 | -import GHC.Internal.Unicode ( isDigit, isAlphaNum )
|
|
| 47 | -import GHC.Internal.Read
|
|
| 48 | 44 | import GHC.Internal.Show
|
| 49 | -import GHC.Internal.Text.ParserCombinators.ReadP
|
|
| 50 | -import GHC.Internal.Text.Read ( read )
|
|
| 51 | 45 | |
| 52 | 46 | {- |
|
| 53 | 47 | A 'Version' represents the version of a software entity.
|
| ... | ... | @@ -69,8 +63,8 @@ operations are the right thing for every 'Version'. |
| 69 | 63 | |
| 70 | 64 | Similarly, concrete representations of versions may differ. One
|
| 71 | 65 | possible concrete representation is provided (see 'showVersion' and
|
| 72 | -'parseVersion'), but depending on the application a different concrete
|
|
| 73 | -representation may be more appropriate.
|
|
| 66 | +'Data.Version.parseVersion'), but depending on the application a
|
|
| 67 | +different concrete representation may be more appropriate.
|
|
| 74 | 68 | -}
|
| 75 | 69 | data Version =
|
| 76 | 70 | Version { versionBranch :: [Int],
|
| ... | ... | @@ -92,8 +86,7 @@ data Version = |
| 92 | 86 | -- The interpretation of the list of tags is entirely dependent
|
| 93 | 87 | -- on the entity that this version applies to.
|
| 94 | 88 | }
|
| 95 | - deriving ( Read -- ^ @since base-2.01
|
|
| 96 | - , Show -- ^ @since base-2.01
|
|
| 89 | + deriving ( Show -- ^ @since base-2.01
|
|
| 97 | 90 | )
|
| 98 | 91 | {-# DEPRECATED versionTags "See GHC ticket #2496" #-}
|
| 99 | 92 | -- TODO. Remove all references to versionTags in GHC 8.0 release.
|
| ... | ... | @@ -120,13 +113,6 @@ showVersion (Version branch tags) |
| 120 | 113 | = concat (intersperse "." (map show branch)) ++
|
| 121 | 114 | concatMap ('-':) tags
|
| 122 | 115 | |
| 123 | --- | A parser for versions in the format produced by 'showVersion'.
|
|
| 124 | ---
|
|
| 125 | -parseVersion :: ReadP Version
|
|
| 126 | -parseVersion = do branch <- sepBy1 (fmap read (munch1 isDigit)) (char '.')
|
|
| 127 | - tags <- many (char '-' *> munch1 isAlphaNum)
|
|
| 128 | - pure Version{versionBranch=branch, versionTags=tags}
|
|
| 129 | - |
|
| 130 | 116 | -- | Construct tag-less 'Version'
|
| 131 | 117 | --
|
| 132 | 118 | -- @since base-4.8.0.0
|
| 1 | -{-# LANGUAGE Trustworthy #-}
|
|
| 2 | -{-# LANGUAGE NoImplicitPrelude #-}
|
|
| 3 | - |
|
| 4 | ------------------------------------------------------------------------------
|
|
| 5 | --- |
|
|
| 6 | --- Module : GHC.Internal.Text.Read
|
|
| 7 | --- Copyright : (c) The University of Glasgow 2001
|
|
| 8 | --- License : BSD-style (see the file libraries/base/LICENSE)
|
|
| 9 | ---
|
|
| 10 | --- Maintainer : libraries@haskell.org
|
|
| 11 | --- Stability : provisional
|
|
| 12 | --- Portability : non-portable (uses Text.ParserCombinators.ReadP)
|
|
| 13 | ---
|
|
| 14 | --- Converting strings to values.
|
|
| 15 | ---
|
|
| 16 | --- The "Text.Read" library is the canonical library to import for
|
|
| 17 | --- 'Read'-class facilities. For GHC only, it offers an extended and much
|
|
| 18 | --- improved 'Read' class, which constitutes a proposed alternative to the
|
|
| 19 | --- Haskell 2010 'Read'. In particular, writing parsers is easier, and
|
|
| 20 | --- the parsers are much more efficient.
|
|
| 21 | ---
|
|
| 22 | ------------------------------------------------------------------------------
|
|
| 23 | - |
|
| 24 | -module GHC.Internal.Text.Read (
|
|
| 25 | - -- * The 'Read' class
|
|
| 26 | - Read(..),
|
|
| 27 | - ReadS,
|
|
| 28 | - |
|
| 29 | - -- * Haskell 2010 functions
|
|
| 30 | - reads,
|
|
| 31 | - read,
|
|
| 32 | - readParen,
|
|
| 33 | - lex,
|
|
| 34 | - |
|
| 35 | - -- * New parsing functions
|
|
| 36 | - module GHC.Internal.Text.ParserCombinators.ReadPrec,
|
|
| 37 | - L.Lexeme(..),
|
|
| 38 | - lexP,
|
|
| 39 | - parens,
|
|
| 40 | - readListDefault,
|
|
| 41 | - readListPrecDefault,
|
|
| 42 | - readEither,
|
|
| 43 | - readMaybe
|
|
| 44 | - |
|
| 45 | - ) where
|
|
| 46 | - |
|
| 47 | -import GHC.Internal.Base (String, id, return)
|
|
| 48 | -import GHC.Internal.Err (errorWithoutStackTrace)
|
|
| 49 | -import GHC.Internal.Maybe (Maybe(..))
|
|
| 50 | -import GHC.Internal.Read
|
|
| 51 | -import GHC.Internal.Data.Either
|
|
| 52 | -import GHC.Internal.Text.ParserCombinators.ReadP as P
|
|
| 53 | -import GHC.Internal.Text.ParserCombinators.ReadPrec
|
|
| 54 | -import qualified GHC.Internal.Text.Read.Lex as L
|
|
| 55 | - |
|
| 56 | --- $setup
|
|
| 57 | --- >>> import Prelude
|
|
| 58 | - |
|
| 59 | -------------------------------------------------------------------------
|
|
| 60 | --- utility functions
|
|
| 61 | - |
|
| 62 | --- | equivalent to 'readsPrec' with a precedence of 0.
|
|
| 63 | -reads :: Read a => ReadS a
|
|
| 64 | -reads = readsPrec minPrec
|
|
| 65 | - |
|
| 66 | --- | Parse a string using the 'Read' instance.
|
|
| 67 | --- Succeeds if there is exactly one valid result.
|
|
| 68 | --- A 'Left' value indicates a parse error.
|
|
| 69 | ---
|
|
| 70 | --- >>> readEither "123" :: Either String Int
|
|
| 71 | --- Right 123
|
|
| 72 | ---
|
|
| 73 | --- >>> readEither "hello" :: Either String Int
|
|
| 74 | --- Left "Prelude.read: no parse"
|
|
| 75 | ---
|
|
| 76 | --- @since base-4.6.0.0
|
|
| 77 | -readEither :: Read a => String -> Either String a
|
|
| 78 | -readEither s =
|
|
| 79 | - case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of
|
|
| 80 | - [x] -> Right x
|
|
| 81 | - [] -> Left "Prelude.read: no parse"
|
|
| 82 | - _ -> Left "Prelude.read: ambiguous parse"
|
|
| 83 | - where
|
|
| 84 | - read' =
|
|
| 85 | - do x <- readPrec
|
|
| 86 | - lift P.skipSpaces
|
|
| 87 | - return x
|
|
| 88 | - |
|
| 89 | --- | Parse a string using the 'Read' instance.
|
|
| 90 | --- Succeeds if there is exactly one valid result.
|
|
| 91 | ---
|
|
| 92 | --- >>> readMaybe "123" :: Maybe Int
|
|
| 93 | --- Just 123
|
|
| 94 | ---
|
|
| 95 | --- >>> readMaybe "hello" :: Maybe Int
|
|
| 96 | --- Nothing
|
|
| 97 | ---
|
|
| 98 | --- @since base-4.6.0.0
|
|
| 99 | -readMaybe :: Read a => String -> Maybe a
|
|
| 100 | -readMaybe s = case readEither s of
|
|
| 101 | - Left _ -> Nothing
|
|
| 102 | - Right a -> Just a
|
|
| 103 | - |
|
| 104 | --- | The 'read' function reads input from a string, which must be
|
|
| 105 | --- completely consumed by the input process. 'read' fails with an 'error' if the
|
|
| 106 | --- parse is unsuccessful, and it is therefore discouraged from being used in
|
|
| 107 | --- real applications. Use 'readMaybe' or 'readEither' for safe alternatives.
|
|
| 108 | ---
|
|
| 109 | --- >>> read "123" :: Int
|
|
| 110 | --- 123
|
|
| 111 | ---
|
|
| 112 | --- >>> read "hello" :: Int
|
|
| 113 | --- *** Exception: Prelude.read: no parse
|
|
| 114 | -read :: Read a => String -> a
|
|
| 115 | -read s = either errorWithoutStackTrace id (readEither s) |
| ... | ... | @@ -12496,7 +12496,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi |
| 12496 | 12496 | instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
|
| 12497 | 12497 | instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
|
| 12498 | 12498 | instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
|
| 12499 | -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
|
|
| 12499 | +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
|
|
| 12500 | 12500 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12501 | 12501 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12502 | 12502 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
|
| ... | ... | @@ -12545,13 +12545,12 @@ instance [safe] GHC.Internal.Read.Read GHC.Stats.RTSStats -- Defined in ‘GHC.S |
| 12545 | 12545 | instance GHC.Internal.Read.Read GHC.Internal.TypeNats.SomeNat -- Defined in ‘GHC.Internal.TypeNats’
|
| 12546 | 12546 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeChar -- Defined in ‘GHC.Internal.TypeLits’
|
| 12547 | 12547 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeSymbol -- Defined in ‘GHC.Internal.TypeLits’
|
| 12548 | -instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12549 | 12548 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.BufferMode -- Defined in ‘System.IO’
|
| 12550 | 12549 | instance GHC.Internal.Read.Read GHC.Internal.IO.IOMode.IOMode -- Defined in ‘System.IO’
|
| 12551 | 12550 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.Newline -- Defined in ‘System.IO’
|
| 12552 | 12551 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.NewlineMode -- Defined in ‘System.IO’
|
| 12553 | 12552 | instance GHC.Internal.Read.Read GHC.Internal.IO.Device.SeekMode -- Defined in ‘System.IO’
|
| 12554 | -instance forall a k (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12553 | +instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12555 | 12554 | instance forall a. GHC.Internal.Float.RealFloat a => GHC.Internal.Real.Fractional (Data.Complex.Complex a) -- Defined in ‘Data.Complex’
|
| 12556 | 12555 | instance forall k (a :: k). Data.Fixed.HasResolution a => GHC.Internal.Real.Fractional (Data.Fixed.Fixed a) -- Defined in ‘Data.Fixed’
|
| 12557 | 12556 | instance forall k1 k2 (f :: k1 -> *) (g :: k2 -> k1) (a :: k2). GHC.Internal.Real.Fractional (f (g a)) => GHC.Internal.Real.Fractional (Data.Functor.Compose.Compose f g a) -- Defined in ‘Data.Functor.Compose’
|
| ... | ... | @@ -12525,7 +12525,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi |
| 12525 | 12525 | instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
|
| 12526 | 12526 | instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
|
| 12527 | 12527 | instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
|
| 12528 | -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
|
|
| 12528 | +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
|
|
| 12529 | 12529 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12530 | 12530 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12531 | 12531 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
|
| ... | ... | @@ -12574,13 +12574,12 @@ instance [safe] GHC.Internal.Read.Read GHC.Stats.RTSStats -- Defined in ‘GHC.S |
| 12574 | 12574 | instance GHC.Internal.Read.Read GHC.Internal.TypeNats.SomeNat -- Defined in ‘GHC.Internal.TypeNats’
|
| 12575 | 12575 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeChar -- Defined in ‘GHC.Internal.TypeLits’
|
| 12576 | 12576 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeSymbol -- Defined in ‘GHC.Internal.TypeLits’
|
| 12577 | -instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12578 | 12577 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.BufferMode -- Defined in ‘System.IO’
|
| 12579 | 12578 | instance GHC.Internal.Read.Read GHC.Internal.IO.IOMode.IOMode -- Defined in ‘System.IO’
|
| 12580 | 12579 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.Newline -- Defined in ‘System.IO’
|
| 12581 | 12580 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.NewlineMode -- Defined in ‘System.IO’
|
| 12582 | 12581 | instance GHC.Internal.Read.Read GHC.Internal.IO.Device.SeekMode -- Defined in ‘System.IO’
|
| 12583 | -instance forall a k (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12582 | +instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12584 | 12583 | instance forall a. GHC.Internal.Float.RealFloat a => GHC.Internal.Real.Fractional (Data.Complex.Complex a) -- Defined in ‘Data.Complex’
|
| 12585 | 12584 | instance forall k (a :: k). Data.Fixed.HasResolution a => GHC.Internal.Real.Fractional (Data.Fixed.Fixed a) -- Defined in ‘Data.Fixed’
|
| 12586 | 12585 | instance forall k1 k2 (f :: k1 -> *) (g :: k2 -> k1) (a :: k2). GHC.Internal.Real.Fractional (f (g a)) => GHC.Internal.Real.Fractional (Data.Functor.Compose.Compose f g a) -- Defined in ‘Data.Functor.Compose’
|
| ... | ... | @@ -12767,7 +12767,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi |
| 12767 | 12767 | instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
|
| 12768 | 12768 | instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
|
| 12769 | 12769 | instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
|
| 12770 | -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
|
|
| 12770 | +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
|
|
| 12771 | 12771 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12772 | 12772 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12773 | 12773 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
|
| ... | ... | @@ -12817,13 +12817,12 @@ instance [safe] GHC.Internal.Read.Read GHC.Stats.RTSStats -- Defined in ‘GHC.S |
| 12817 | 12817 | instance GHC.Internal.Read.Read GHC.Internal.TypeNats.SomeNat -- Defined in ‘GHC.Internal.TypeNats’
|
| 12818 | 12818 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeChar -- Defined in ‘GHC.Internal.TypeLits’
|
| 12819 | 12819 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeSymbol -- Defined in ‘GHC.Internal.TypeLits’
|
| 12820 | -instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12821 | 12820 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.BufferMode -- Defined in ‘System.IO’
|
| 12822 | 12821 | instance GHC.Internal.Read.Read GHC.Internal.IO.IOMode.IOMode -- Defined in ‘System.IO’
|
| 12823 | 12822 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.Newline -- Defined in ‘System.IO’
|
| 12824 | 12823 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.NewlineMode -- Defined in ‘System.IO’
|
| 12825 | 12824 | instance GHC.Internal.Read.Read GHC.Internal.IO.Device.SeekMode -- Defined in ‘System.IO’
|
| 12826 | -instance forall a k (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12825 | +instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12827 | 12826 | instance forall a. GHC.Internal.Float.RealFloat a => GHC.Internal.Real.Fractional (Data.Complex.Complex a) -- Defined in ‘Data.Complex’
|
| 12828 | 12827 | instance forall k (a :: k). Data.Fixed.HasResolution a => GHC.Internal.Real.Fractional (Data.Fixed.Fixed a) -- Defined in ‘Data.Fixed’
|
| 12829 | 12828 | instance forall k1 k2 (f :: k1 -> *) (g :: k2 -> k1) (a :: k2). GHC.Internal.Real.Fractional (f (g a)) => GHC.Internal.Real.Fractional (Data.Functor.Compose.Compose f g a) -- Defined in ‘Data.Functor.Compose’
|
| ... | ... | @@ -12496,7 +12496,7 @@ instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semi |
| 12496 | 12496 | instance forall a. GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Semigroup.Min a) -- Defined in ‘Data.Semigroup’
|
| 12497 | 12497 | instance forall m. GHC.Internal.Read.Read m => GHC.Internal.Read.Read (Data.Semigroup.WrappedMonoid m) -- Defined in ‘Data.Semigroup’
|
| 12498 | 12498 | instance forall k (a :: k) (b :: k). Coercible a b => GHC.Internal.Read.Read (GHC.Internal.Data.Type.Coercion.Coercion a b) -- Defined in ‘GHC.Internal.Data.Type.Coercion’
|
| 12499 | -instance GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘GHC.Internal.Data.Version’
|
|
| 12499 | +instance [safe] GHC.Internal.Read.Read GHC.Internal.Data.Version.Version -- Defined in ‘Data.Version’
|
|
| 12500 | 12500 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.IntPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12501 | 12501 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.Ptr.WordPtr -- Defined in ‘GHC.Internal.Foreign.Ptr’
|
| 12502 | 12502 | instance GHC.Internal.Read.Read GHC.Internal.Foreign.C.Types.CBool -- Defined in ‘GHC.Internal.Foreign.C.Types’
|
| ... | ... | @@ -12545,13 +12545,12 @@ instance [safe] GHC.Internal.Read.Read GHC.Stats.RTSStats -- Defined in ‘GHC.S |
| 12545 | 12545 | instance GHC.Internal.Read.Read GHC.Internal.TypeNats.SomeNat -- Defined in ‘GHC.Internal.TypeNats’
|
| 12546 | 12546 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeChar -- Defined in ‘GHC.Internal.TypeLits’
|
| 12547 | 12547 | instance GHC.Internal.Read.Read GHC.Internal.TypeLits.SomeSymbol -- Defined in ‘GHC.Internal.TypeLits’
|
| 12548 | -instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12549 | 12548 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.BufferMode -- Defined in ‘System.IO’
|
| 12550 | 12549 | instance GHC.Internal.Read.Read GHC.Internal.IO.IOMode.IOMode -- Defined in ‘System.IO’
|
| 12551 | 12550 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.Newline -- Defined in ‘System.IO’
|
| 12552 | 12551 | instance GHC.Internal.Read.Read GHC.Internal.IO.Handle.Types.NewlineMode -- Defined in ‘System.IO’
|
| 12553 | 12552 | instance GHC.Internal.Read.Read GHC.Internal.IO.Device.SeekMode -- Defined in ‘System.IO’
|
| 12554 | -instance forall a k (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12553 | +instance forall k a (b :: k). GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (GHC.Internal.Data.Functor.Const.Const a b) -- Defined in ‘GHC.Internal.Data.Functor.Const’
|
|
| 12555 | 12554 | instance forall a. GHC.Internal.Float.RealFloat a => GHC.Internal.Real.Fractional (Data.Complex.Complex a) -- Defined in ‘Data.Complex’
|
| 12556 | 12555 | instance forall k (a :: k). Data.Fixed.HasResolution a => GHC.Internal.Real.Fractional (Data.Fixed.Fixed a) -- Defined in ‘Data.Fixed’
|
| 12557 | 12556 | instance forall k1 k2 (f :: k1 -> *) (g :: k2 -> k1) (a :: k2). GHC.Internal.Real.Fractional (f (g a)) => GHC.Internal.Real.Fractional (Data.Functor.Compose.Compose f g a) -- Defined in ‘Data.Functor.Compose’
|
| ... | ... | @@ -2,6 +2,7 @@ parsePlugin() |
| 2 | 2 | interfacePlugin: Prelude
|
| 3 | 3 | interfacePlugin: Language.Haskell.TH
|
| 4 | 4 | interfacePlugin: Language.Haskell.TH.Quote
|
| 5 | +interfacePlugin: Data.Version
|
|
| 5 | 6 | interfacePlugin: System.IO
|
| 6 | 7 | interfacePlugin: GHC.Internal.Base
|
| 7 | 8 | interfacePlugin: GHC.Internal.Data.NonEmpty
|