MonadFail with type parameter for error message

Dear Cafe, MonadFail.fail takes String. I wasn't able to find MonadFail for custom error type. Is there any proposals to base? Let's say Data.Text, which gains popularity with OverloadedStrings extensions. class MonadFail m where fail :: String -> m a Why not ? class MonadFail m where fail :: (forall s. IsString s => s) -> m a class MonadFailWith m s where fail :: s -> m a -- Best regards, Daniil Iaitskov

Because the primary purpose of fail is to provide for failed pattern
matches, which invoke it with a String representing the pattern match
error.
On Tue, Nov 30, 2021 at 2:16 PM Daneel Yaitskov
Dear Cafe,
MonadFail.fail takes String. I wasn't able to find MonadFail for custom error type. Is there any proposals to base?
Let's say Data.Text, which gains popularity with OverloadedStrings extensions.
class MonadFail m where fail :: String -> m a
Why not ? class MonadFail m where fail :: (forall s. IsString s => s) -> m a
class MonadFailWith m s where fail :: s -> m a
--
Best regards, Daniil Iaitskov
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

On Tue, Nov 30, 2021 at 2:20 PM Brandon Allbery
Because the primary purpose of fail is to provide for failed pattern matches, which invoke it with a String representing the pattern match error.
I see the purpose, but fail with just literal string is not very informative. It is easier for debugging supplying an error message with Showable parameters. Custom Prelude has show :: a - >Text so fail looks like: oops -> fail $ "functionX is not implemented for " <> show oops
On Tue, Nov 30, 2021 at 2:16 PM Daneel Yaitskov
wrote: Dear Cafe,
MonadFail.fail takes String. I wasn't able to find MonadFail for custom error type. Is there any proposals to base?
Let's say Data.Text, which gains popularity with OverloadedStrings
extensions.
class MonadFail m where fail :: String -> m a
Why not ? class MonadFail m where fail :: (forall s. IsString s => s) -> m a
class MonadFailWith m s where fail :: s -> m a
--
Best regards, Daniil Iaitskov
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com
-- Best regards, Daniil Iaitskov

Because that wouldn't actually help. You couldn't optimize it for different
stringy types. Using instance overlap (which is evil), you *could* do
something similar.
class Monad m => MonadFail s m where
fail :: s -> m a
instance {-# OVERLAPPABLE #-} (MonadFail String m, IsString s) => MonadFail
s m where
fail = fail . toString
I don't think this is terribly likely to work well in practice.
On Tue, Nov 30, 2021, 2:16 PM Daneel Yaitskov
Dear Cafe,
MonadFail.fail takes String. I wasn't able to find MonadFail for custom error type. Is there any proposals to base?
Let's say Data.Text, which gains popularity with OverloadedStrings extensions.
class MonadFail m where fail :: String -> m a
Why not ? class MonadFail m where fail :: (forall s. IsString s => s) -> m a
class MonadFailWith m s where fail :: s -> m a
--
Best regards, Daniil Iaitskov
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (3)
-
Brandon Allbery
-
Daneel Yaitskov
-
David Feuer