2024/10/25

Newest at the top

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 +0200LukeHoersten(~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 +0200merijn(~merijn@128-137-045-062.dynamic.caiway.nl) (Ping timeout: 272 seconds)
2024-10-25 20:19:27 +0200 <tomsmeding> er, wait
2024-10-25 20:19:17 +0200 <tomsmeding> it has the same problem
2024-10-25 20:19:15 +0200 <tomsmeding> ok so then your type of this 'init' field is wrong
2024-10-25 20:19:05 +0200 <tomsmeding> ah
2024-10-25 20:19:02 +0200alp(~alp@2001:861:e3d6:8f80:55e8:1aad:506c:464b) (Remote host closed the connection)
2024-10-25 20:18:57 +0200 <lxsameer> https://git.sr.ht/~lxsameer/Feynman/tree/master/item/src/Feynman/DB/Postgres.hs#L32
2024-10-25 20:18:50 +0200 <lxsameer> tomsmeding: yeah
2024-10-25 20:18:43 +0200 <lxsameer> so my main question is, since UsageError is postgres related only, how can I generalize the error here?
2024-10-25 20:18:41 +0200 <tomsmeding> lxsameer: so you want to be able to say "DB { init = pgInit _ _, insert = _, finalize = _ }"?
2024-10-25 20:17:53 +0200 <lxsameer> tomsmeding: I use to use SomeException like the rest, i just changed it
2024-10-25 20:17:50 +0200 <tomsmeding> the idea is that 'init' is polymorphic in the usual sense, so its type has a forall; but then that means that if you _use_ the field, you don't know what type 'e' was used when calling 'init', so the field behaves like an existential
2024-10-25 20:17:21 +0200 <tomsmeding> written using 'forall' because the syntax is confusing
2024-10-25 20:17:12 +0200 <tomsmeding> lxsameer: that 'init' field contains an existential e