2025/12/04

Newest at the top

2025-12-04 14:50:21 +0100lambda_gibbon(~lambda_gi@2603:7080:ee00:37d8:313d:1898:c3f8:5287) (Ping timeout: 265 seconds)
2025-12-04 14:44:05 +0100 <lucabtz> even though i suppose it could have an use somewhere
2025-12-04 14:43:53 +0100 <lucabtz> no that version isnt what i need
2025-12-04 14:43:04 +0100 <ski> (.. not too sure how useful this version would be for you .. just pondering)
2025-12-04 14:42:27 +0100 <ski> (assuming you use `<' rather than `<=')
2025-12-04 14:42:12 +0100ski. o O ( `(+) :: BoundedNatural m -> BoundedNatural n -> BoundedNatural (m + n)' )
2025-12-04 14:40:41 +0100Lord_of_Life(~Lord@user/lord-of-life/x-2819915) (Quit: Laa shay'a waqi'un moutlaq bale kouloun moumkine)
2025-12-04 14:40:30 +0100 <ski> mhm
2025-12-04 14:40:17 +0100 <lucabtz> (:?) :: a -> a -> Maybe a
2025-12-04 14:39:57 +0100 <lucabtz> ski i have a new typeclass PartialAdditive with an operator +?
2025-12-04 14:39:22 +0100 <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 14:39:16 +0100fp(~Thunderbi@wireless-86-50-141-176.open.aalto.fi) fp
2025-12-04 14:38:00 +0100fp(~Thunderbi@2001:708:20:1406::1370) (Ping timeout: 252 seconds)
2025-12-04 14:37:17 +0100 <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 14:37:14 +0100trickard_trickard
2025-12-04 14:35:28 +0100 <ski> how are you detecting over- / under- flow ?
2025-12-04 14:33:41 +0100trickard_(~trickard@cpe-85-98-47-163.wireline.com.au)
2025-12-04 14:33:27 +0100trickard_(~trickard@cpe-85-98-47-163.wireline.com.au) (Read error: Connection reset by peer)
2025-12-04 14:32:50 +0100 <ski> aha
2025-12-04 14:32:12 +0100 <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 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 +0100ljdarj(~Thunderbi@user/ljdarj) (Ping timeout: 240 seconds)
2025-12-04 14:21:16 +0100pavonia(~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 +0100fp(~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 +0100fp(~Thunderbi@130.233.70.22) (Quit: fp)
2025-12-04 14:12:22 +0100trickard_(~trickard@cpe-85-98-47-163.wireline.com.au)
2025-12-04 14:12:08 +0100trickard_(~trickard@cpe-85-98-47-163.wireline.com.au) (Read error: Connection reset by peer)