Newest at the top
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) |
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 +0200 | alp | (~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 |
2024-10-25 20:17:10 +0200 | <lxsameer> | this is the interface that I want to have so each backend can just populate that record with the common operations |
2024-10-25 20:16:46 +0200 | alp | (~alp@2001:861:e3d6:8f80:55e8:1aad:506c:464b) |
2024-10-25 20:16:42 +0200 | <lxsameer> | tomsmeding: ok it's getting more confusing. check this out: https://git.sr.ht/~lxsameer/Feynman/tree/master/item/src/Feynman/DB/Core.hs#L41 |
2024-10-25 20:15:51 +0200 | <tomsmeding> | giving the particular instantiation of the existential is _more_ information than just returning an existential |
2024-10-25 20:15:33 +0200 | merijn | (~merijn@128-137-045-062.dynamic.caiway.nl) merijn |
2024-10-25 20:15:26 +0200 | <tomsmeding> | er, not even newtype, 'data' that |
2024-10-25 20:15:21 +0200 | <tomsmeding> | because what you really intended to write here is ... -> IO (Maybe (exists e. Exception e => e)), except Haskell doesn't support existential types like that so you have to 'newtype' that |
2024-10-25 20:15:14 +0200 | sord937 | (~sord937@gateway/tor-sasl/sord937) (Quit: sord937) |
2024-10-25 20:15:11 +0200 | <lxsameer> | let me show you more, give me a sec |
2024-10-25 20:14:53 +0200 | <tomsmeding> | (in a sense) |
2024-10-25 20:14:45 +0200 | <tomsmeding> | so you're not making your interface any less flexible |