Logs: liberachat/#haskell
| 2025-10-20 16:48:34 | <EvanR> | they're answered by the type signature? xD |
| 2025-10-20 16:48:52 | <haskellbridge> | <Morj> :D |
| 2025-10-20 16:49:08 | <haskellbridge> | <Morj> No yeah but hoogle is so great. I miss it every day I write in rust |
| 2025-10-20 16:49:30 | × | kimiamania99 quits (~92460e22@user/kimiamania) (Quit: PegeLinux) |
| 2025-10-20 16:50:41 | → | flipflops joins (~cmo@2604:3d09:207f:8000::d1dc) |
| 2025-10-20 16:59:11 | × | tromp quits (~textual@2001:1c00:3487:1b00:242b:79a0:e1f9:7ea5) (Quit: My iMac has gone to sleep. ZZZzzz…) |
| 2025-10-20 17:04:41 | <haskellbridge> | <doc> is there a way to auto derive instances like Num a => Num (Foo a) where { (+) = liftA2 (+); (-) = liftA2 (-); (_) = liftA2 (_); abs = fmap abs; fromInteger = pure . fromInteger; etc etc} where Foo is an applicative and all the methods just plumb fmap/liftA, liftA2, and pure… I read a thread on r/haskell abt this and it was recommended to write this out for each type you need this for, which is perfectly fine, but am curious if there's any... |
| 2025-10-20 17:04:47 | <haskellbridge> | ... deriving magic that can do this |
| 2025-10-20 17:06:04 | × | kubrat quits (~kubrat@149.62.205.137) (Quit: Client closed) |
| 2025-10-20 17:07:06 | × | flipflops quits (~cmo@2604:3d09:207f:8000::d1dc) (Ping timeout: 252 seconds) |
| 2025-10-20 17:08:31 | <geekosaur> | no auto derive, but you can in fact write an instance that works for any Applicative |
| 2025-10-20 17:09:16 | <geekosaur> | the main argument against is that it leads to unexpected behavior, mostly due to ((->) e) being Applicative |
| 2025-10-20 17:10:37 | × | Googulator30 quits (~Googulato@2a01-036d-0106-03fa-0485-6a66-0733-0e38.pool6.digikabel.hu) (Quit: Client closed) |
| 2025-10-20 17:10:42 | → | Googulator67 joins (~Googulato@2a01-036d-0106-03fa-0485-6a66-0733-0e38.pool6.digikabel.hu) |
| 2025-10-20 17:13:03 | <geekosaur> | instance (Applicative f, Num a) => Num (f a) where (+) = liftA2 (+); (-) = liftA2 (-); (*) = liftA2 (*); negate = fmap negate; abs = fmap abs; signum = fmap signum; fromInteger = pure . fromInteger |
| 2025-10-20 17:13:22 | → | wootehfoot joins (~wootehfoo@user/wootehfoot) |
| 2025-10-20 17:14:06 | <geekosaur> | this and Num polymorphism means using that instance is a good way to induce insanity |
| 2025-10-20 17:14:30 | <haskellbridge> | <doc> yep this was also mentioned on that discussion i read, to avoid having this general instance in scope |
| 2025-10-20 17:14:54 | <geekosaur> | it shouldn't be difficult to write some TH to auto-derive it |
| 2025-10-20 17:17:58 | → | kubrat joins (~kubrat@149.62.205.137) |
| 2025-10-20 17:18:12 | → | qqe joins (~qqq@185.54.23.200) |
| 2025-10-20 17:20:23 | × | kubrat quits (~kubrat@149.62.205.137) (Client Quit) |
| 2025-10-20 17:31:05 | → | mastarija joins (~mastarija@89-164-108-176.dsl.iskon.hr) |
| 2025-10-20 17:31:22 | → | tromp joins (~textual@2001:1c00:3487:1b00:242b:79a0:e1f9:7ea5) |
| 2025-10-20 17:32:12 | <mastarija> | Is there a way to recover the actual type from generics? The type names are written out as a type level string, but I'd like to somehow recover the original type. |
| 2025-10-20 17:32:31 | <mastarija> | I'd like to construct a type level list of all the field types of a product type. |
| 2025-10-20 17:33:59 | <mastarija> | I'm thinking it might be possible to hack a HasField + type family to get the fields since there's a functional dependency between the parent type, type level field name and the type of the field. |
| 2025-10-20 17:34:37 | <mastarija> | But that will only work on product types that have field names (if it's even possible to use HasField like that). |
| 2025-10-20 17:35:27 | <geekosaur> | I think the actual type is available, but not that way. Generics are built on Data.Data iirc, which should allow getting the actual type I think? |
| 2025-10-20 17:36:09 | <mastarija> | Hm... interesting. I did not know that. |
| 2025-10-20 17:37:47 | <geekosaur> | my recollection is Generics <- Data.Data <- Typeable, but while Typeable has the type available in some sense it's not powerful enough to make it directly available; the best you can do is its `cast` which produces a `Maybe targetType` |
| 2025-10-20 17:38:17 | <geekosaur> | that said, it's entirely possible I remember wrong and Data.Data is the basis for a different generics implementation (SYB seems most likely in that case) |
| 2025-10-20 17:38:32 | <mastarija> | Yeah. They mention something about that. |
| 2025-10-20 17:38:33 | <tomsmeding> | I'm fairly sure Data.Data is not involved here |
| 2025-10-20 17:38:41 | <tomsmeding> | Data.Data is untyped, and GHC.Generics is quite typed |
| 2025-10-20 17:38:42 | <mastarija> | I think Typeable is not what I want. |
| 2025-10-20 17:39:00 | <geekosaur> | it's not; like I said, it's not strong enough |
| 2025-10-20 17:39:07 | <tomsmeding> | mastarija: which type exactly are you looking for? The type of a field? |
| 2025-10-20 17:39:35 | <mastarija> | Like, my ultimate goal is to be able to make a `toTuple` / `fromTuple` instances where I could generically convert any product type into a tuple. |
| 2025-10-20 17:39:51 | <mastarija> | But yes. Type of a field is what I'm looking for. |
| 2025-10-20 17:39:58 | <tomsmeding> | the field types are simply there inside the Rec0 constructors |
| 2025-10-20 17:40:16 | <mastarija> | When using `Rep` I unfortunatelly do not get that. |
| 2025-10-20 17:40:21 | <mastarija> | Wait, really? |
| 2025-10-20 17:40:26 | <tomsmeding> | % :seti -XDeriveGeneric |
| 2025-10-20 17:40:26 | <yahb2> | <no output> |
| 2025-10-20 17:40:32 | <tomsmeding> | % data A = A Int Bool deriving (Generic) |
| 2025-10-20 17:40:32 | <yahb2> | <interactive>:63:31: error: [GHC-76037] ; Not in scope: type constructor or class ‘Generic’ |
| 2025-10-20 17:40:37 | <tomsmeding> | % import GHC.Generics |
| 2025-10-20 17:40:37 | <yahb2> | <no output> |
| 2025-10-20 17:40:39 | → | ljdarj joins (~Thunderbi@user/ljdarj) |
| 2025-10-20 17:40:40 | <tomsmeding> | % data A = A Int Bool deriving (Generic) |
| 2025-10-20 17:40:40 | <yahb2> | <no output> |
| 2025-10-20 17:40:43 | <geekosaur> | yes |
| 2025-10-20 17:40:43 | <tomsmeding> | %% :k! Rep A |
| 2025-10-20 17:40:43 | <yahb2> | https://paste.tomsmeding.com/UQWaOWBa |
| 2025-10-20 17:40:53 | <tomsmeding> | note the Int and Bool in there |
| 2025-10-20 17:41:05 | <tomsmeding> | I don't even see any string forms anywhere |
| 2025-10-20 17:41:39 | <mastarija> | But will that work for a field that's another product? I just want to go one level deep. |
| 2025-10-20 17:42:28 | <tomsmeding> | what do you mean? Do you have a simple example type? |
| 2025-10-20 17:42:32 | <mastarija> | Huh. It does. |
| 2025-10-20 17:42:35 | <dcpagan> | Did "join" used to be a class method that one could optionally define for a Monad instance? I could have sworn that I read somewhere that you could define a Monad instance by defining join instead of defining bind, since m >>= k = join $ fmap k m |
| 2025-10-20 17:42:39 | <mastarija> | I don't know what I was thinking. |
| 2025-10-20 17:42:50 | <monochrom> | I don't think join was ever a method. |
| 2025-10-20 17:42:53 | <tomsmeding> | dcpagan: well you can always define (>>=) in terms of join yourself |
| 2025-10-20 17:43:03 | <mastarija> | Yeah. I guess on Rec0 we are supposed to manually call Rep if we want to go deeper, right? |
| 2025-10-20 17:43:11 | <mastarija> | Now it's coming back to me... |
| 2025-10-20 17:43:15 | <tomsmeding> | if you want to recurse into a field, then yes |
| 2025-10-20 17:43:55 | <mastarija> | Yeah. Thanks. I somehow misremembered stuff and got stuck thinking my thinking is correct xD |
| 2025-10-20 17:43:57 | <monochrom> | Not sure what you read, but generally "could" could (pun!) be highly hypothetical as in "in another parallel universe" and/or "if I were World Dictator". |
| 2025-10-20 17:44:30 | <dolio> | Is that a pun? |
| 2025-10-20 17:47:20 | <monochrom> | Could be! |
| 2025-10-20 17:47:25 | × | wbrawner quits (~wbrawner@static.56.224.132.142.clients.your-server.de) (Ping timeout: 264 seconds) |
| 2025-10-20 17:47:33 | → | wbrawner joins (~wbrawner@static.56.224.132.142.clients.your-server.de) |
| 2025-10-20 17:53:17 | → | ephilalethes joins (~noumenon@113.51-175-156.customer.lyse.net) |
| 2025-10-20 17:53:26 | × | ephilalethes quits (~noumenon@113.51-175-156.customer.lyse.net) (Remote host closed the connection) |
| 2025-10-20 17:55:04 | → | flipflops joins (~cmo@2604:3d09:207f:8000::d1dc) |
| 2025-10-20 18:05:43 | × | Googulator67 quits (~Googulato@2a01-036d-0106-03fa-0485-6a66-0733-0e38.pool6.digikabel.hu) (Quit: Client closed) |
| 2025-10-20 18:05:44 | → | Googulator7 joins (~Googulato@2a01-036d-0106-03fa-0485-6a66-0733-0e38.pool6.digikabel.hu) |
| 2025-10-20 18:09:35 | → | Natch joins (~natch@c-92-34-15-120.bbcust.telenor.se) |
| 2025-10-20 18:10:54 | × | flipflops quits (~cmo@2604:3d09:207f:8000::d1dc) (Ping timeout: 252 seconds) |
| 2025-10-20 18:11:44 | → | yabobay joins (~pizza@2a02:85f:fcd5:1601:439e:d9b3:6a5d:d567) |
| 2025-10-20 18:12:13 | <yabobay> | is there a generic version of splitWith somewhere in the standard library? or at least one that works on String's? |
| 2025-10-20 18:13:00 | <EvanR> | what do you mean by generic, maybe write the desired type signature |
| 2025-10-20 18:14:44 | <yabobay> | (a -> Bool) -> [a] -> http://en.wikipedia.org/wiki/Special:Search?go=Go&search=a |
| 2025-10-20 18:14:51 | <yabobay> | uh |
| 2025-10-20 18:15:02 | <EvanR> | :t breakOn |
| 2025-10-20 18:15:03 | <lambdabot> | error: |
| 2025-10-20 18:15:04 | <lambdabot> | • Variable not in scope: breakOn |
| 2025-10-20 18:15:04 | <lambdabot> | • Perhaps you meant one of these: |
| 2025-10-20 18:15:17 | <EvanR> | :t break |
| 2025-10-20 18:15:18 | <lambdabot> | (a -> Bool) -> [a] -> ([a], [a]) |
| 2025-10-20 18:15:40 | <yabobay> | well what if i want it to break at every delimiter instead of just the first one |
| 2025-10-20 18:15:50 | <yabobay> | and so return a list |
| 2025-10-20 18:15:56 | <EvanR> | that is a pretty simple combination of break and scanl |
| 2025-10-20 18:16:10 | <EvanR> | which I reimplemented a few times |
| 2025-10-20 18:16:20 | <EvanR> | there is a package with a bunch of splitting utilities |
| 2025-10-20 18:16:23 | <yabobay> | you can probably write it easily but gimme a moment to figure it out for fun |
| 2025-10-20 18:16:32 | <EvanR> | it's called `split' |
| 2025-10-20 18:16:52 | <yabobay> | you mean the package? |
| 2025-10-20 18:16:55 | <EvanR> | yeah |
All times are in UTC.