Newest at the top
2024-10-25 20:26:56 +0200 | <tomsmeding> | unless you very carefully vet what you call |
2024-10-25 20:26:49 +0200 | <tomsmeding> | so even if you neatly _return_ an exception, you might still accidentally throw one |
2024-10-25 20:26:39 +0200 | Flerix | (Flerix@user/Flerix) (Quit: Leaving) |
2024-10-25 20:26:37 +0200 | <tomsmeding> | just be mindful that other functions that _you_ are calling might also throw IO exceptions, unbeknownst to you |
2024-10-25 20:26:13 +0200 | <tomsmeding> | lxsameer: right, throwIO is the usual way to throw exceptions in IO code; but if you want to return them for some reason, the best way would be toException (well found) |
2024-10-25 20:26:13 +0200 | <EvanR> | very bad |
2024-10-25 20:26:12 +0200 | <EvanR> | no good |
2024-10-25 20:26:07 +0200 | <EvanR> | awful, terrible |
2024-10-25 20:25:50 +0200 | <lambdabot> | Exception e => e -> a |
2024-10-25 20:25:49 +0200 | <EvanR> | :t throw |
2024-10-25 20:25:47 +0200 | <EvanR> | non-IO might also use throw |
2024-10-25 20:25:24 +0200 | <EvanR> | like they didn't put all the case analysis cases, or they did division by zero, or evaluated an infinite loop |
2024-10-25 20:25:23 +0200 | <lxsameer> | cool, so the first suggestion is throwIO and then the approach above, right |
2024-10-25 20:25:00 +0200 | <EvanR> | but still might for weird reasons |
2024-10-25 20:24:53 +0200 | <EvanR> | non-IO is ideally not failing |
2024-10-25 20:24:40 +0200 | <tomsmeding> | yes that's called toException |
2024-10-25 20:24:40 +0200 | <EvanR> | yeah IO is prone to failing |
2024-10-25 20:24:36 +0200 | <tomsmeding> | oh |
2024-10-25 20:24:26 +0200 | <tomsmeding> | yes |
2024-10-25 20:24:18 +0200 | <tomsmeding> | lxsameer: just write `return . Just . SomeException` |
2024-10-25 20:24:14 +0200 | <lxsameer> | EvanR: ah, so it's kinda in the IOs contract that it might throw Exception |
2024-10-25 20:24:13 +0200 | <EvanR> | thanks, clear as mud lol |
2024-10-25 20:24:05 +0200 | <yahb2> | SomeException ; :: (Exception e, ; GHC.Internal.Exception.Type.HasExceptionContext) => ; e -> SomeException |
2024-10-25 20:24:05 +0200 | <tomsmeding> | % :t SomeException |
2024-10-25 20:23:50 +0200 | <yahb2> | type SomeException :: * ; data SomeException ; = forall e. ; (Exception e, GHC.Internal.Exception.Type.HasExceptionContext) => ; SomeException e ; -- Defined in ‘GHC.Internal.Exception... |
2024-10-25 20:23:50 +0200 | <tomsmeding> | % :i SomeException |
2024-10-25 20:23:43 +0200 | <lxsameer> | tomsmeding: to whenLeft Nothing migrationResult (return . Just . toException) right? |
2024-10-25 20:23:27 +0200 | <lxsameer> | tomsmeding: ok, if I use SomeException. the I have to change the https://git.sr.ht/~lxsameer/Feynman/tree/master/item/src/Feynman/DB/Postgres.hs#L52 |
2024-10-25 20:23:20 +0200 | <tomsmeding> | because SomeException literally means "this is a thing that implements Exception, but I forgot what precise type it was" |
2024-10-25 20:23:11 +0200 | <EvanR> | actually evaluating any value may throw some exception, but not by using throwIO |
2024-10-25 20:22:52 +0200 | <tomsmeding> | lxsameer: I would recommend using SomeException |
2024-10-25 20:22:22 +0200 | <EvanR> | there's no "checked exceptions" |
2024-10-25 20:22:12 +0200 | <EvanR> | lxsameer, there's no indication. Any IO action when executed might throw an exception |
2024-10-25 20:22:08 +0200 | <tomsmeding> | lxsameer: as you can see here, with this DB type, if you project the 'init' field from a DB value, you get back an IO (Maybe e) for an e that _you can choose_ |
2024-10-25 20:21:44 +0200 | <tomsmeding> | lol |
2024-10-25 20:21:42 +0200 | <tomsmeding> | what I said previously about the field type was wrong |
2024-10-25 20:20:59 +0200 | LukeHoersten | (~LukeHoers@user/lukehoersten) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
2024-10-25 20:20:54 +0200 | <tomsmeding> | lxsameer: you can't |
2024-10-25 20:20:52 +0200 | <yahb2> | \x -> init x :: Exception e => DB -> IO (Maybe e) |
2024-10-25 20:20:52 +0200 | <tomsmeding> | % :t \x -> init x |
2024-10-25 20:20:47 +0200 | <lxsameer> | EvanR: that throwIO, still returns IO a, how can I tell by the type that this function may throw? |
2024-10-25 20:20:46 +0200 | <yahb2> | init :: DB -> forall e. Exception e => IO (Maybe e) |
2024-10-25 20:20:46 +0200 | <tomsmeding> | % :t init |
2024-10-25 20:20:38 +0200 | <yahb2> | init :: DB -> forall e. Exception e => IO (Maybe e) |
2024-10-25 20:20:37 +0200 | <tomsmeding> | % :t init |
2024-10-25 20:20:36 +0200 | <yahb2> | <no output> |
2024-10-25 20:20:35 +0200 | <tomsmeding> | % data DB = DB { init :: forall e. Exception e => IO (Maybe e) } |
2024-10-25 20:20:33 +0200 | <yahb2> | <no output> |
2024-10-25 20:20:33 +0200 | <tomsmeding> | % import Control.Exception |
2024-10-25 20:20:10 +0200 | merijn | (~merijn@128-137-045-062.dynamic.caiway.nl) (Ping timeout: 272 seconds) |