readMaybe

Parse a string using the Read instance. Succeeds if there is exactly one valid result.
>>> readMaybe "123" :: Maybe Int
Just 123
>>> readMaybe "hello" :: Maybe Int
Nothing
Parse a string using the Read instance. Succeeds if there is exactly one valid result.
>>> readMaybe ("123" :: Text) :: Maybe Int
Just 123
>>> readMaybe ("hello" :: Text) :: Maybe Int
Nothing
Parse a string using the Read instance. Succeeds if there is exactly one valid result.
>>> readMaybe "123" :: Maybe Int
Just 123
>>> readMaybe "hello" :: Maybe Int
Nothing
@since base-4.6.0.0
Polymorhpic version of readMaybe.
>>> readMaybe @Int @Text "123"
Just 123

>>> readMaybe @Int @Text "aa"
Nothing
Inspired by the: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Maybe.html Is provided here as a more general way to read the String into a EncodedCnstrs. It is up to user to check whether the parameters are in the correct form, the function does not do the full checking.
>>> greadMaybe "InL Refl" mkSome :: Maybe (Some (Sum ((:~:) Int) ((:~:) Bool)))
Just (mkSome (InL Refl))
>>> greadMaybe "L1 Refl" mkSome :: Maybe (Some ((:~:) Int :+: (:~:) Bool))
Just (mkSome (L1 Refl))
>>> greadMaybe "garbage" mkSome :: Maybe (Some ((:~:) Int))
Nothing