Newest at the top
| 2025-12-04 14:31:16 +0100 | <lucabtz> | *the grid based problems in advent of code |
| 2025-12-04 14:31:01 +0100 | <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 14:31:01 +0100 | <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 14:30:46 +0100 | <lucabtz> | thank you |
| 2025-12-04 14:30:31 +0100 | <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 14:29:25 +0100 | <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 14:27:47 +0100 | <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 14:25:37 +0100 | <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 14:24:06 +0100 | <lucabtz> | i wouldnt export UnsafeMkBoundedInteger |
| 2025-12-04 14:23:54 +0100 | <lucabtz> | it seems like this would be the case for me |
| 2025-12-04 14:23:51 +0100 | <lambdabot> | array (-3,3) [(-3,(-3,9)),(-2,(-2,4)),(-1,(-1,1)),(0,(0,0)),(1,(1,1)),(2,(2,... |
| 2025-12-04 14:23:47 +0100 | <ski> | > listArray (-3,3) [(i,i^2) | i <- range (-3,3)] |
| 2025-12-04 14:23:46 +0100 | <tomsmeding> | c0? |
| 2025-12-04 14:23:12 +0100 | <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 14:22:32 +0100 | ljdarj | (~Thunderbi@user/ljdarj) (Ping timeout: 240 seconds) |
| 2025-12-04 14:21:16 +0100 | pavonia | (~user@user/siracusa) (Quit: Bye!) |
| 2025-12-04 14:20:48 +0100 | <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 14:19:28 +0100 | <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 14:16:08 +0100 | <ski> | which is confusing and not that useful |
| 2025-12-04 14:16:02 +0100 | <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 14:14:52 +0100 | <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 14:14:09 +0100 | <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 14:13:47 +0100 | <tomsmeding> | (agreed with ski) |
| 2025-12-04 14:13:34 +0100 | <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 14:13:22 +0100 | <lucabtz> | and i need the bound as part of the type |
| 2025-12-04 14:13:12 +0100 | fp | (~Thunderbi@2001:708:20:1406::1370) fp |
| 2025-12-04 14:13:05 +0100 | <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 14:12:50 +0100 | fp | (~Thunderbi@130.233.70.22) (Quit: fp) |
| 2025-12-04 14:12:22 +0100 | trickard_ | (~trickard@cpe-85-98-47-163.wireline.com.au) |
| 2025-12-04 14:12:08 +0100 | trickard_ | (~trickard@cpe-85-98-47-163.wireline.com.au) (Read error: Connection reset by peer) |
| 2025-12-04 14:10:55 +0100 | <tomsmeding> | https://hackage.haskell.org/package/base-4.19.0.0/docs/GHC-TypeNats.html#t:-60--61- |
| 2025-12-04 14:10:23 +0100 | <tomsmeding> | lucabtz: while that is possible, bounds on the type level like that tend to make for very cumbersome interfaces |
| 2025-12-04 14:10:17 +0100 | <lucabtz> | i just needed a way to print the stuff to the terminal |
| 2025-12-04 14:10:05 +0100 | <lucabtz> | yeah i havent studied in detail Read/Show i find them confusing |
| 2025-12-04 14:09:29 +0100 | <ski> | (`showsPrec p (PromiseBoundedNatural n) = showParen (p > 10) $ showString "PromiseBoundedNatural " . showsPrec 11 n' is how i'd do `Show', if no `fromInteger' for `BoundedNatural bound') |
| 2025-12-04 14:09:27 +0100 | <lucabtz> | i think mkBoundedNatural should have a different signature taking the bound into account too. it should be done with SNat |
| 2025-12-04 14:09:20 +0100 | Square2 | (~Square4@user/square) Square |
| 2025-12-04 14:07:50 +0100 | <lucabtz> | i will look better into it later |
| 2025-12-04 14:07:27 +0100 | <ski> | mm, yea, that would be possible |
| 2025-12-04 14:06:48 +0100 | <ski> | (also i'd implement `fromInteger', or else i'd say that `Show' instance is incorrect) |
| 2025-12-04 14:06:45 +0100 | <tomsmeding> | oh what might be even nicer is to keep UnsafeMkBoundedNatural, but provide a pattern synonym (Mk)BoundedNatural that does a dynamic check on construction |
| 2025-12-04 14:06:16 +0100 | Typosit | (b41a81e702@2001:bc8:1210:2cd8::494) (Write error: error:80000068:system library::Connection reset by peer) |
| 2025-12-04 14:05:24 +0100 | <ski> | lucabtz : fwiw, i'd s/UnsafeMkBoundedNatural/PromiseBoundedNatural/, indicating that by using the constructor, you promise that the argument/component is bounded, and that by pattern-matching, you are being promised that the component is bounded |
| 2025-12-04 14:04:12 +0100 | Typosit | (b41a81e702@2001:bc8:1210:2cd8::494) |
| 2025-12-04 14:03:08 +0100 | PaulMartensen | (15a119e437@2001:bc8:1210:2cd8::3bc) (Ping timeout: 256 seconds) |
| 2025-12-04 14:03:03 +0100 | annamalai | (~annamalai@157.32.218.49) annamalai |
| 2025-12-04 13:59:45 +0100 | X-Scale | (~ARM@50.65.114.89.rev.vodafone.pt) X-Scale |
| 2025-12-04 13:59:07 +0100 | Ging_ | (46fea76d80@2001:bc8:1210:2cd8::470) (Ping timeout: 265 seconds) |
| 2025-12-04 13:59:07 +0100 | Typosit | (b41a81e702@2001:bc8:1210:2cd8::494) (Ping timeout: 265 seconds) |
| 2025-12-04 13:58:59 +0100 | <tomsmeding> | lucabtz: what do you mean with that? |