Logs: liberachat/#haskell
| 2021-05-28 17:03:52 | <dminuoso> | (Dont know from the top off my head whether that would satisfy functor laws, naively Id say yes but I dont have a good reason) |
| 2021-05-28 17:03:54 | × | dmwit quits (~dmwit@pool-173-66-86-32.washdc.fios.verizon.net) (Ping timeout: 264 seconds) |
| 2021-05-28 17:04:27 | <dminuoso> | oh hold on |
| 2021-05-28 17:04:32 | <dminuoso> | `instance Functor Foo where fmap f (Foo pair) = Foo (bimap f f pair)` |
| 2021-05-28 17:04:36 | <dminuoso> | forgot one argument to bimap there |
| 2021-05-28 17:05:19 | <monochrom> | :) |
| 2021-05-28 17:05:27 | → | bitmapper joins (uid464869@id-464869.tooting.irccloud.com) |
| 2021-05-28 17:05:39 | <hololeap> | ok, let's nail this down to something concrete by explaining my actual problem. |
| 2021-05-28 17:05:44 | → | dmwit joins (~dmwit@pool-173-66-86-32.washdc.fios.verizon.net) |
| 2021-05-28 17:05:46 | <hololeap> | data IsComplete a = Touched (ValidityWrapper a a) | Untouched |
| 2021-05-28 17:05:48 | × | v01d4lph4 quits (~v01d4lph4@user/v01d4lph4) (Remote host closed the connection) |
| 2021-05-28 17:06:05 | <dminuoso> | Is ValidityWrapper a Bifunctor? |
| 2021-05-28 17:06:21 | <hololeap> | no, ValidityWrapper has kind (Type -> Type) |
| 2021-05-28 17:06:33 | <dminuoso> | Dont lie to me. |
| 2021-05-28 17:06:35 | → | Bartosz joins (~textual@50.35.215.151) |
| 2021-05-28 17:06:40 | <dminuoso> | It clearly has Type -> Type -> Type |
| 2021-05-28 17:06:48 | → | v01d4lph4 joins (~v01d4lph4@user/v01d4lph4) |
| 2021-05-28 17:06:50 | × | ubikium quits (~ubikium@113x43x248x70.ap113.ftth.arteria-hikari.net) (Ping timeout: 244 seconds) |
| 2021-05-28 17:06:52 | <hololeap> | it's a type family defined in a class |
| 2021-05-28 17:06:55 | <dminuoso> | Oh. |
| 2021-05-28 17:06:57 | <dminuoso> | A tyfam |
| 2021-05-28 17:07:01 | → | ubikium joins (~ubikium@113x43x248x70.ap113.ftth.arteria-hikari.net) |
| 2021-05-28 17:07:04 | → | monadlight joins (~chris@bras-vprn-nwmkon8540w-lp130-19-184-147-249-234.dsl.bell.ca) |
| 2021-05-28 17:07:07 | dminuoso | scrolls up to see if he missed that bit |
| 2021-05-28 17:07:09 | <hololeap> | yeah, I mentioned that way at the top |
| 2021-05-28 17:07:10 | <hololeap> | :) |
| 2021-05-28 17:07:15 | <monadlight> | Why is <$ useful as one of the Functor methods? |
| 2021-05-28 17:07:39 | <monochrom> | That just lost a lot of functoriality and naturality and parametricity... |
| 2021-05-28 17:07:39 | <dminuoso> | monadlight: It's frequently useful for when you want to override the "result" but still gain effects, usually in applicative/monadic code. |
| 2021-05-28 17:07:54 | × | chele quits (~chele@user/chele) (Remote host closed the connection) |
| 2021-05-28 17:08:31 | <monadlight> | dminuoso: that's deep... |
| 2021-05-28 17:08:42 | <hololeap> | the idea for IsComplete is that it encodes whether or not a field has been "touched" in a form. For instance, if I have a "Text" field, then an empty value might be valid, but I want to mark whether or not the user has "touched" it |
| 2021-05-28 17:08:48 | <dminuoso> | monadlight: Consider a simple parser |
| 2021-05-28 17:09:14 | <dminuoso> | Say you have something that just wants to consume digits, but you absolutely dont care about the digits themselves. |
| 2021-05-28 17:09:17 | <dminuoso> | Then you might write: |
| 2021-05-28 17:09:31 | <dminuoso> | () <$ some digit |
| 2021-05-28 17:09:35 | <dminuoso> | i.e. |
| 2021-05-28 17:09:37 | → | wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2021-05-28 17:09:45 | → | Guest2189 joins (~Guest21@121-75-79-99.dyn.vf.net.nz) |
| 2021-05-28 17:09:47 | <dminuoso> | consumeDigits :: Parser (); consumeDigits = () <$ some digit |
| 2021-05-28 17:09:58 | <hololeap> | The reason for (ValidityWrapper a) is that some types may need an extra wrapper that encodes if the underlying data is valid or not, for instance, with an Int, the text "abcd" needs to be stored as the user types it, but it needs to also mark it as invalid |
| 2021-05-28 17:10:06 | <monochrom> | If I want to implement "press enter to continue" I might use "fmap (\_ -> ()) getLine" which is a use case of <$ |
| 2021-05-28 17:10:07 | <dminuoso> | You can of course also write `someDigit >> pure ()` or `someDigit >> return ()` - but often its useful to just start with what you return on the left side |
| 2021-05-28 17:10:41 | <dminuoso> | monadlight: Let me pull some examples from our network compiler |
| 2021-05-28 17:10:53 | × | merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 252 seconds) |
| 2021-05-28 17:11:20 | → | boxscape joins (~boxscape@user/boxscape) |
| 2021-05-28 17:11:31 | <hololeap> | now, at this point I don't actually _need_ a Functor instance for IsComplete, but after trying to write a StandaloneDeriving instance I started to wonder if it was even possible in case I might need it later on |
| 2021-05-28 17:11:31 | <monadlight> | I think I understand what you mean but I'm still a newbie |
| 2021-05-28 17:12:09 | <dminuoso> | monadlight: https://gist.github.com/dminuoso/53fbd686b59a5f79adb58af773f54294 |
| 2021-05-28 17:12:57 | <dminuoso> | monadlight: Here Nothing being on the left side immediately communicates "Return Nothing as the result", but on the right side I still set an error (imagine me writing this error to a log perhaps) |
| 2021-05-28 17:13:47 | <monadlight> | I can see that it's clearer and more consistent that way |
| 2021-05-28 17:14:04 | × | wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 244 seconds) |
| 2021-05-28 17:14:29 | dminuoso | idly wonders why he doesnt use traverseOf instead, there. |
| 2021-05-28 17:15:40 | <monadlight> | It's a comfort for newbie to see that Haskell can be used for parsing network data :-) |
| 2021-05-28 17:15:44 | × | khumba quits (~khumba@S01066038e0ca1250.ok.shawcable.net) (Changing host) |
| 2021-05-28 17:15:44 | → | khumba joins (~khumba@user/khumba) |
| 2021-05-28 17:16:05 | × | rahguzar quits (~rahguzar@212.189.140.214) (Ping timeout: 272 seconds) |
| 2021-05-28 17:16:08 | <dminuoso> | This code stack is what drives and provisions our core network at $work :) |
| 2021-05-28 17:16:38 | <monadlight> | GHC is not just a giant multi-gigabyte pure calculator. LOL |
| 2021-05-28 17:16:55 | <monochrom> | bc is. |
| 2021-05-28 17:17:27 | <monadlight> | bc is only 235K on my laptop. :-) |
| 2021-05-28 17:17:35 | <monochrom> | Yeah, apart from that. |
| 2021-05-28 17:18:33 | <dminuoso> | monadlight: Also, if you put it along side with $>, <* and *> you get a nice selection of combinators to play with |
| 2021-05-28 17:19:20 | <hololeap> | type instance ValidityWrapper Text = Identity , type instance ValidityWrapper Word8 = IsValid Text |
| 2021-05-28 17:19:30 | × | myShoggoth quits (~myShoggot@97-120-89-117.ptld.qwest.net) (Ping timeout: 264 seconds) |
| 2021-05-28 17:19:52 | <dminuoso> | hololeap: With ValidityWrapper being a tyfam, Im going to say you are not getting a Functor instance here. |
| 2021-05-28 17:19:53 | <monadlight> | Dilbert cartoon, telling evil boss he's found a bunch of combinators to play with this weekend. Hence, project is delayed. :-) |
| 2021-05-28 17:20:07 | <hololeap> | dminuoso: ok, noted :) |
| 2021-05-28 17:20:25 | → | wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2021-05-28 17:20:48 | × | a6a45081-2b83 quits (~aditya@106.212.79.20) (Read error: Connection reset by peer) |
| 2021-05-28 17:21:20 | × | holy_ quits (~h01y_b4z0@2400:adc1:178:c800:9e45:76a9:57f2:1665) (Ping timeout: 252 seconds) |
| 2021-05-28 17:21:54 | × | blurgy quits (~blurgy@blurgy.xyz) (Quit: WeeChat 3.1) |
| 2021-05-28 17:22:28 | → | blurgy joins (~blurgy@blurgy.xyz) |
| 2021-05-28 17:22:38 | ← | blurgy parts (~blurgy@blurgy.xyz) () |
| 2021-05-28 17:24:05 | → | eggplant_ joins (~Eggplanta@2600:1700:bef1:5e10:2038:b31a:2642:e4ef) |
| 2021-05-28 17:24:08 | → | gzj joins (~GZJ0X@185.212.59.97.16clouds.com) |
| 2021-05-28 17:24:20 | × | noddy quits (~self@user/noddy) (Quit: (λω.ωω)(λω.ωω)) |
| 2021-05-28 17:24:42 | → | noddy joins (~self@user/noddy) |
| 2021-05-28 17:25:15 | <dminuoso> | hololeap: Also, you still lied about the type of ValidityWrapper |
| 2021-05-28 17:25:22 | × | wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 264 seconds) |
| 2021-05-28 17:25:28 | × | argento quits (~argent0@168.227.96.51) (Ping timeout: 264 seconds) |
| 2021-05-28 17:25:43 | <dminuoso> | If `ValidityWrapper :: Type -> Type`, then you simply cant have `data IsComplete a = Touched (ValidityWrapper a a) | Untouched` |
| 2021-05-28 17:25:46 | <dminuoso> | It wouldn't kind check |
| 2021-05-28 17:26:01 | → | coot joins (~coot@37.30.49.19.nat.umts.dynamic.t-mobile.pl) |
| 2021-05-28 17:26:01 | × | raehik quits (~raehik@cpc95906-rdng25-2-0-cust156.15-3.cable.virginm.net) (Ping timeout: 272 seconds) |
| 2021-05-28 17:26:02 | <dminuoso> | You need `ValidityWrapper :: Type -> Type -> Type` |
| 2021-05-28 17:26:36 | <dminuoso> | Since you were quite confident about the type of ValidityWrapper, Im wondering there's a mixup here. |
| 2021-05-28 17:26:42 | × | eggplantade quits (~Eggplanta@2600:1700:bef1:5e10:b043:8b77:c7da:42a0) (Ping timeout: 264 seconds) |
| 2021-05-28 17:26:57 | <dminuoso> | % type family ValidityWrapper a = b |
| 2021-05-28 17:26:57 | <yahb> | dminuoso: |
| 2021-05-28 17:27:09 | <dminuoso> | % data IsComplete a = Touched (ValidityWrapper a a) | Untouched -- hololeap |
| 2021-05-28 17:27:09 | <yahb> | dminuoso: ; <interactive>:80:30: error:; * Expected kind `* -> *', but `ValidityWrapper a' has kind `*'; * In the type `(ValidityWrapper a a)'; In the definition of data constructor `Touched'; In the data declaration for `IsComplete' |
| 2021-05-28 17:27:10 | × | xff0x quits (~xff0x@2001:1a81:53fe:8d00:3833:823b:7d79:69a2) (Ping timeout: 248 seconds) |
| 2021-05-28 17:27:50 | → | raehik joins (~raehik@cpc95906-rdng25-2-0-cust156.15-3.cable.virginm.net) |
| 2021-05-28 17:27:52 | × | sondre quits (~sondrelun@eduroam-193-157-188-96.wlan.uio.no) (Ping timeout: 264 seconds) |
| 2021-05-28 17:27:57 | <dminuoso> | % type family ValidityWrapper a = (b :: * -> *) |
| 2021-05-28 17:27:57 | <yahb> | dminuoso: |
| 2021-05-28 17:28:00 | <dminuoso> | % data IsComplete a = Touched (ValidityWrapper a a) | Untouched -- hololeap |
| 2021-05-28 17:28:00 | <yahb> | dminuoso: |
| 2021-05-28 17:28:04 | <dminuoso> | % :k ValidityWrapper |
All times are in UTC.