Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,801,907 events total
2025-12-04 13:10:05 <lucabtz> yeah i havent studied in detail Read/Show i find them confusing
2025-12-04 13:10:17 <lucabtz> i just needed a way to print the stuff to the terminal
2025-12-04 13:10:23 <tomsmeding> lucabtz: while that is possible, bounds on the type level like that tend to make for very cumbersome interfaces
2025-12-04 13:10:55 <tomsmeding> https://hackage.haskell.org/package/base-4.19.0.0/docs/GHC-TypeNats.html#t:-60--61-
2025-12-04 13:12:08 × trickard_ quits (~trickard@cpe-85-98-47-163.wireline.com.au) (Read error: Connection reset by peer)
2025-12-04 13:12:22 trickard_ joins (~trickard@cpe-85-98-47-163.wireline.com.au)
2025-12-04 13:12:50 × fp quits (~Thunderbi@130.233.70.22) (Quit: fp)
2025-12-04 13:13:05 <lucabtz> i think the check has to be kept at runtime, because i need to determine the type at runtime, however i want the type to extend another typeclass which i called PartialAdditive which supports an operator +? which may fail and a zero
2025-12-04 13:13:12 fp joins (~Thunderbi@2001:708:20:1406::1370)
2025-12-04 13:13:22 <lucabtz> and i need the bound as part of the type
2025-12-04 13:13:34 <ski> lucabtz : imho, (a) `Show' ought to use Haskell syntax (rather than some custom syntax format), so that its `String' output (in an appropriate environment) will evaluate to an equal value; and (b) if you also have `Read', then it ought to be able to read (finite) output generated from `Show', producing an equal value
2025-12-04 13:13:47 <tomsmeding> (agreed with ski)
2025-12-04 13:14:09 <lucabtz> if it was something like data BoundedNatural = { val :: Natural, bound :: Natural } then zero would not make sense because how do you pick a bound
2025-12-04 13:14:52 <lucabtz> ski yeah i realized last night when i was trying to understand Read and i saw it is so much related to haskell lexicon itself
2025-12-04 13:16:02 <ski> (a) means that, normally, if defining `Show' explicitly (rather than `deriving'), you'll normally define `showsPrec', to deal with precdedence and bracketing properly. do note that different `Show' instances are intended to work together (e.g. `instance Show a => Show (Maybe a)'), so that if you happen to use custom syntax for `T', you'll then get a mix of custom and Haskell syntax for (e.g.) `Maybe T',
2025-12-04 13:16:08 <ski> which is confusing and not that useful
2025-12-04 13:19:28 <ski> *if* your output will never need extra brackets, you can define `show' instead. do note that getting the brackets properly printed in `Just (-1)' relies on defining `showsPrec' for the number type, so that `Just' can tell it the precedence level (of application, being `11' for the argument expression, see example above), so that `-1' will know to wrap itself in brackets, when `showsPrec' is called on it
2025-12-04 13:20:48 <ski> (for your case, `Natural's can't be negative, so this issue doesn't arise there. this was just one example of why `showsPrec' is needed)
2025-12-04 13:21:16 × pavonia quits (~user@user/siracusa) (Quit: Bye!)
2025-12-04 13:22:32 × ljdarj quits (~Thunderbi@user/ljdarj) (Ping timeout: 240 seconds)
2025-12-04 13:23:12 <ski> common valid reasons for wanting to custom-define `Show' (and `Read') are (c0) you want to have an abstract data type, not exporting data constructors, so `Show' should show how to construct the value in terms of exported operations instead (and similarly for the `Read' case, parsing that). e.g. `Array',`Set',`Map' does this
2025-12-04 13:23:46 <tomsmeding> c0?
2025-12-04 13:23:47 <ski> > listArray (-3,3) [(i,i^2) | i <- range (-3,3)]
2025-12-04 13:23:51 <lambdabot> array (-3,3) [(-3,(-3,9)),(-2,(-2,4)),(-1,(-1,1)),(0,(0,0)),(1,(1,1)),(2,(2,...
2025-12-04 13:23:54 <lucabtz> it seems like this would be the case for me
2025-12-04 13:24:06 <lucabtz> i wouldnt export UnsafeMkBoundedInteger
2025-12-04 13:25:37 <ski> and (c1) you want to use `fromInteger' (or similar hooks into literal syntax for other things, e.g. overloaded string literals), and so you'd probably want `Read' to be able to parse that, and possibly want `Show' to produce it
2025-12-04 13:27:47 <ski> also (c2), if you have infix operator declarations for some data constructors, and you want your `Show' to omit unnecessary brackets (when showing in infix form), since iirc GHC for some reason ignores the fixities when `deriving' `Show'
2025-12-04 13:29:25 <ski> i not too seldom also do (c3) define a data type with record notation for some data constructors, but i don't want `Show' to use the record syntax (because it's verbose, when you're trying to read some larger output), which is what the `deriving' syntax will give you, in this case
2025-12-04 13:30:31 <ski> (i'd possibly still define `Read' to accept both record notation and plain data constructor with components as arguments version, though)
2025-12-04 13:30:46 <lucabtz> thank you
2025-12-04 13:31:01 <lucabtz> yeah the whole point for me is having an interface which supports partial addition, in which the sum of two numbers may not be defined. maybe im just overthinking, its for the grid based problems. i want this abstraction because i can change the grid type by changing the coordinate types, if i put bounded integers when asking for neighbours they maybe be 8 or less (because you may exit the
2025-12-04 13:31:01 <lucabtz> grid). on the other hand i could have a type which does addition in a modular way and get a toroidal grid. i wanted to write the code once to support both options
2025-12-04 13:31:16 <lucabtz> *the grid based problems in advent of code
2025-12-04 13:32:12 <ski> otoh, if you want some custom pretty-printing syntax, i'd suggest not using `Show' (nor `Read') for this, rather defining separate functions (or perhaps using some other type class, possibly one you defined yourself)
2025-12-04 13:32:50 <ski> aha
2025-12-04 13:33:27 × trickard_ quits (~trickard@cpe-85-98-47-163.wireline.com.au) (Read error: Connection reset by peer)
2025-12-04 13:33:41 trickard_ joins (~trickard@cpe-85-98-47-163.wireline.com.au)
2025-12-04 13:35:28 <ski> how are you detecting over- / under- flow ?
2025-12-04 13:37:14 trickard_ is now known as trickard
2025-12-04 13:37:17 <ski> lucabtz : yep, so either you could have `Show' generate a call to `mkBoundedNatural'. or, if you do the pattern synonym, you could have it generate a call to that
2025-12-04 13:38:00 × fp quits (~Thunderbi@2001:708:20:1406::1370) (Ping timeout: 252 seconds)
2025-12-04 13:39:16 fp joins (~Thunderbi@wireless-86-50-141-176.open.aalto.fi)
2025-12-04 13:39:22 <ski> (oh, and the corresponding operation handling precedences, for `Read', would be `readsPrec', which you'd define in terms of `readParen',`readsPrec',`lex'. for `Show' there's also `showChar')
2025-12-04 13:39:57 <lucabtz> ski i have a new typeclass PartialAdditive with an operator +?
2025-12-04 13:40:17 <lucabtz> (:?) :: a -> a -> Maybe a
2025-12-04 13:40:30 <ski> mhm
2025-12-04 13:40:41 × Lord_of_Life quits (~Lord@user/lord-of-life/x-2819915) (Quit: Laa shay'a waqi'un moutlaq bale kouloun moumkine)
2025-12-04 13:42:12 ski . o O ( `(+) :: BoundedNatural m -> BoundedNatural n -> BoundedNatural (m + n)' )
2025-12-04 13:42:27 <ski> (assuming you use `<' rather than `<=')
2025-12-04 13:43:04 <ski> (.. not too sure how useful this version would be for you .. just pondering)
2025-12-04 13:43:53 <lucabtz> no that version isnt what i need
2025-12-04 13:44:05 <lucabtz> even though i suppose it could have an use somewhere
2025-12-04 13:50:21 × lambda_gibbon quits (~lambda_gi@2603:7080:ee00:37d8:313d:1898:c3f8:5287) (Ping timeout: 265 seconds)
2025-12-04 13:51:58 lambda_gibbon joins (~lambda_gi@2603:7080:ee00:37d8:313d:1898:c3f8:5287)
2025-12-04 13:59:47 × Digit quits (~user@user/digit) (Read error: Connection reset by peer)
2025-12-04 14:02:34 Lord_of_Life joins (~Lord@user/lord-of-life/x-2819915)
2025-12-04 14:03:15 Ging_ joins (46fea76d80@2001:bc8:1210:2cd8::470)
2025-12-04 14:05:40 × tromp quits (~textual@2001:1c00:3487:1b00:a4ed:9e46:fd5d:6b4e) (Quit: My iMac has gone to sleep. ZZZzzz…)
2025-12-04 14:06:36 tromp joins (~textual@2001:1c00:3487:1b00:a4ed:9e46:fd5d:6b4e)
2025-12-04 14:08:29 pr1sm joins (~pr1sm@24.91.163.31)
2025-12-04 14:08:38 × pr1sm quits (~pr1sm@24.91.163.31) (Remote host closed the connection)
2025-12-04 14:10:04 Digit joins (~user@user/digit)
2025-12-04 14:15:44 mikess joins (~sam@user/mikess)
2025-12-04 14:22:22 × fp quits (~Thunderbi@wireless-86-50-141-176.open.aalto.fi) (Quit: fp)
2025-12-04 14:22:32 fp1 joins (~Thunderbi@wireless-86-50-141-176.open.aalto.fi)
2025-12-04 14:23:55 × xff0x quits (~xff0x@2405:6580:b080:900:d454:e7ea:27f9:454f) (Ping timeout: 255 seconds)
2025-12-04 14:24:13 × wbooze quits (~wbooze@2001-4dd4-1daa-0-acf3-bea0-8250-a5a2.ipv6dyn.netcologne.de) (Read error: Connection reset by peer)
2025-12-04 14:24:56 fp1 is now known as fp
2025-12-04 14:27:41 × trickard quits (~trickard@cpe-85-98-47-163.wireline.com.au) (Read error: Connection reset by peer)
2025-12-04 14:27:54 trickard_ joins (~trickard@cpe-85-98-47-163.wireline.com.au)
2025-12-04 14:28:58 divlamir_ joins (~divlamir@user/divlamir)
2025-12-04 14:29:09 × divlamir quits (~divlamir@user/divlamir) (Ping timeout: 252 seconds)
2025-12-04 14:29:49 divlamir_ is now known as divlamir
2025-12-04 14:30:52 wbooze joins (~wbooze@2001-4dd4-1daa-0-dd66-75b6-3dbd-fc23.ipv6dyn.netcologne.de)
2025-12-04 14:35:07 × fp quits (~Thunderbi@wireless-86-50-141-176.open.aalto.fi) (Remote host closed the connection)
2025-12-04 14:46:54 xff0x joins (~xff0x@2405:6580:b080:900:d454:e7ea:27f9:454f)
2025-12-04 14:52:58 chiselfuse joins (~chiselfus@user/chiselfuse)
2025-12-04 14:53:57 × trickard_ quits (~trickard@cpe-85-98-47-163.wireline.com.au) (Read error: Connection reset by peer)
2025-12-04 14:54:10 trickard_ joins (~trickard@cpe-85-98-47-163.wireline.com.au)
2025-12-04 14:55:28 spew joins (~spew@user/spew)
2025-12-04 14:58:38 califax joins (~califax@user/califx)
2025-12-04 14:59:15 gmg joins (~user@user/gehmehgeh)
2025-12-04 14:59:33 ChaiTRex joins (~ChaiTRex@user/chaitrex)
2025-12-04 15:02:16 Sgeo joins (~Sgeo@user/sgeo)
2025-12-04 15:04:08 Typosit joins (b41a81e702@2001:bc8:1210:2cd8::494)
2025-12-04 15:05:49 marinelli joins (~weechat@gateway/tor-sasl/marinelli)
2025-12-04 15:05:58 ec joins (~ec@gateway/tor-sasl/ec)
2025-12-04 15:14:09 × kmein quits (~weechat@user/kmein) (Quit: ciao kakao)
2025-12-04 15:14:57 kmein joins (~weechat@user/kmein)
2025-12-04 15:15:55 × cstml3 quits (~cstml@user/cstml) (Ping timeout: 240 seconds)
2025-12-04 15:16:32 cstml3 joins (~cstml@user/cstml)
2025-12-04 15:24:08 humasect joins (~humasect@dyn-192-249-132-90.nexicom.net)
2025-12-04 15:25:42 × mikess quits (~sam@user/mikess) (Ping timeout: 244 seconds)
2025-12-04 15:31:55 sindu joins (~sindu@2.148.32.207.tmi.telenormobil.no)
2025-12-04 15:36:21 fp joins (~Thunderbi@89-27-10-140.bb.dnainternet.fi)
2025-12-04 15:46:38 × tromp quits (~textual@2001:1c00:3487:1b00:a4ed:9e46:fd5d:6b4e) (Quit: My iMac has gone to sleep. ZZZzzz…)
2025-12-04 15:49:20 × fp quits (~Thunderbi@89-27-10-140.bb.dnainternet.fi) (Remote host closed the connection)
2025-12-04 15:51:42 ttybitnik joins (~ttybitnik@user/wolper)
2025-12-04 15:55:09 × Digit quits (~user@user/digit) (Quit: brb)

All times are in UTC.