Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2021-05-16 18:45:09 × mikoto-chan quits (~mikoto-ch@gateway/tor-sasl/mikoto-chan) (Ping timeout: 240 seconds)
2021-05-16 18:45:39 × Gurkenglas quits (~Gurkengla@unaffiliated/gurkenglas) (Quit: Leaving)
2021-05-16 18:45:52 × wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 252 seconds)
2021-05-16 18:47:26 xenon- joins (~bc817c21@217.29.117.252)
2021-05-16 18:47:28 <charukiewicz> very easy to write such a function with do-notation where you pull each field you need to build a person out of the HashMap and the whole thing returns a Nothing if any of your lookups fail (e.g. name <- lookup "name" personMap)
2021-05-16 18:47:38 notzmv- joins (~zmv@unaffiliated/zmv)
2021-05-16 18:48:20 Sgeo joins (~Sgeo@ool-18b9875e.dyn.optonline.net)
2021-05-16 18:49:07 <a6a45081-2b83> this looks like a valid definition, f = Person <$> (! "name") <*> (! "age")
2021-05-16 18:49:13 jumper149 joins (~jumper149@80.240.31.34)
2021-05-16 18:49:32 <a6a45081-2b83> to avoid the type error that geekosaur pointed out assume that data Person = Person {name :: String, age :: String} deriving (Show, Eq, Ord)
2021-05-16 18:50:38 <a6a45081-2b83> I have 70 fields in dict, and I think this gets quite verbose, although in worst case i'm ok with writing this out
2021-05-16 18:51:21 juuandyy joins (~juuandyy@90.106.228.121)
2021-05-16 18:51:28 <charukiewicz> I'd be careful about using ! since it will return an error if the key isn't in the map
2021-05-16 18:51:44 <charukiewicz> !? is the safe version that will return a maybe
2021-05-16 18:52:24 × notzmv- quits (~zmv@unaffiliated/zmv) (Ping timeout: 265 seconds)
2021-05-16 18:58:31 Gurkenglas joins (~Gurkengla@unaffiliated/gurkenglas)
2021-05-16 18:58:37 rond_ joins (5940206b@89-64-32-107.dynamic.chello.pl)
2021-05-16 18:59:38 Ram-Z joins (Ram-Z@2a01:7e01::f03c:91ff:fe57:d2df)
2021-05-16 18:59:59 × ixlun quits (~user@109.249.184.235) (Ping timeout: 245 seconds)
2021-05-16 19:00:43 ixlun joins (~user@109.249.184.235)
2021-05-16 19:01:01 × tromp quits (~tromp@dhcp-077-249-230-040.chello.nl) (Remote host closed the connection)
2021-05-16 19:02:59 × fendor quits (~fendor@91.141.2.211.wireless.dyn.drei.com) (Read error: Connection reset by peer)
2021-05-16 19:03:02 nicholasbulka joins (~nicholasb@2601:900:4301:da0:b0b3:4831:47cc:ab06)
2021-05-16 19:03:45 ddellacosta joins (ddellacost@gateway/vpn/mullvad/ddellacosta)
2021-05-16 19:05:01 fendor joins (~fendor@91.141.2.211.wireless.dyn.drei.com)
2021-05-16 19:05:26 <a6a45081-2b83> well I found deriveJSON in Data.Aeson.TH that seems helpful
2021-05-16 19:05:31 × ixlun quits (~user@109.249.184.235) (Ping timeout: 252 seconds)
2021-05-16 19:06:18 oish joins (~charlie@228.25.169.217.in-addr.arpa)
2021-05-16 19:06:57 TK__ joins (~cinch@2601:1c0:5201:2100:9992:f75f:4988:2a3c)
2021-05-16 19:08:50 × ddellacosta quits (ddellacost@gateway/vpn/mullvad/ddellacosta) (Ping timeout: 265 seconds)
2021-05-16 19:09:47 × sheepduck quits (~sheepduck@2607:fea8:2a60:b700::cafd) (Ping timeout: 250 seconds)
2021-05-16 19:09:47 royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-05-16 19:10:29 <charukiewicz> yup, we use that all the time in our projects and hardly ever write decoders/encoders by hand
2021-05-16 19:11:04 <charukiewicz> Just define a type that corresponds to what you want your JSON to look like and then run it through deriveJSON to get your ToJSON/FromJSON instances
2021-05-16 19:11:38 ixlun joins (~user@109.249.184.235)
2021-05-16 19:11:38 × ixlun quits (~user@109.249.184.235) (Remote host closed the connection)
2021-05-16 19:11:53 ixlun joins (~user@109.249.184.235)
2021-05-16 19:12:13 <charukiewicz> you can also override the defaultOptions that deriveJSON takes to do things like modify the camel case behavior (so userFirstName becomes user_first_name) or omit a field prefix (userFirstName becomes first_name) when converting from Haskell values to JSON and back again
2021-05-16 19:12:38 × oxide quits (~lambda@unaffiliated/mclaren) (Ping timeout: 252 seconds)
2021-05-16 19:12:40 mikoto-chan joins (~mikoto-ch@gateway/tor-sasl/mikoto-chan)
2021-05-16 19:13:18 <a6a45081-2b83> charukiewicz: they haven't written documentation on what each option does here: https://hackage.haskell.org/package/aeson-1.5.6.0/docs/Data-Aeson-TH.html#t:Options
2021-05-16 19:13:32 × tungki quits (uid469991@gateway/web/irccloud.com/x-xceaiesvmlpclmms) (Quit: Connection closed for inactivity)
2021-05-16 19:13:32 <a6a45081-2b83> some I can gues, some I am not sure
2021-05-16 19:14:09 <charukiewicz> yeah some examples would be helpful. The most common option we override is fieldLabelModifier
2021-05-16 19:14:16 × sord937 quits (~sord937@gateway/tor-sasl/sord937) (Quit: sord937)
2021-05-16 19:14:52 <charukiewicz> So an example of how to use it would be $(deriveJSON defaultOptions{fieldLabelModifier = camelTo2 '_'} ''Person)
2021-05-16 19:15:24 <charukiewicz> This says all camel cased fields in your Haskell record (e.g. firstName) become snake cased (first_name)
2021-05-16 19:16:29 machinedgod joins (~machinedg@24.105.81.50)
2021-05-16 19:16:41 <a6a45081-2b83> nice, what about omitting prefix?
2021-05-16 19:17:58 <charukiewicz> usually our prefixes are a consistent length so we just drop by that length. Here's both camel case and drop prefix composed together: $(deriveJSON defaultOptions{fieldLabelModifier = Prelude.drop 6 . camelTo2 '_'} ''Email)
2021-05-16 19:18:12 × heatsink quits (~heatsink@108-201-191-115.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)
2021-05-16 19:19:23 × idhugo quits (~idhugo@80-62-116-231-mobile.dk.customer.tdc.net) (Ping timeout: 268 seconds)
2021-05-16 19:19:27 wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net)
2021-05-16 19:19:44 × rond_ quits (5940206b@89-64-32-107.dynamic.chello.pl) (Quit: Connection closed)
2021-05-16 19:20:50 xcmw joins (~textual@2603-6011-2200-f103-1090-4073-ea46-f74d.res6.spectrum.com)
2021-05-16 19:23:14 heatsink joins (~heatsink@108-201-191-115.lightspeed.sntcca.sbcglobal.net)
2021-05-16 19:26:39 <a6a45081-2b83> charukiewicz: thanks!
2021-05-16 19:30:10 merijn joins (~merijn@83-160-49-249.ip.xs4all.nl)
2021-05-16 19:30:51 ddellacosta joins (ddellacost@gateway/vpn/mullvad/ddellacosta)
2021-05-16 19:31:32 sheepduck joins (~sheepduck@2607:fea8:2a60:b700::cafd)
2021-05-16 19:34:35 × jumper149 quits (~jumper149@80.240.31.34) (Quit: WeeChat 3.1)
2021-05-16 19:36:07 jumper149 joins (~jumper149@80.240.31.34)
2021-05-16 19:36:15 × jumper149 quits (~jumper149@80.240.31.34) (Client Quit)
2021-05-16 19:36:47 gedda joins (~gedda@s176125235103.blix.com)
2021-05-16 19:38:45 <gedda> category theory question, isn't the Functor typeclass actually Endofunctor?
2021-05-16 19:39:20 <gedda> since fmap remains in the same functor, or am I missing something?
2021-05-16 19:40:02 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Quit: Connection closed)
2021-05-16 19:40:20 royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-05-16 19:40:26 × xcmw quits (~textual@2603-6011-2200-f103-1090-4073-ea46-f74d.res6.spectrum.com) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2021-05-16 19:40:57 <boxscape> Yes, generally speaking the category theory analogies only concern themselves with the single category of Haskell types, "Hask"
2021-05-16 19:41:34 jumper joins (~jumper@gateway/tor-sasl/jumper149)
2021-05-16 19:41:48 <boxscape> though.. I'm not sure the reason you're saying it should be an Endofunctor is the correct reason
2021-05-16 19:42:04 × jumper quits (~jumper@gateway/tor-sasl/jumper149) (Client Quit)
2021-05-16 19:42:24 <gedda> boxscape, i suspected my argument was flawed. Just picked up Bartosz book/blogposts
2021-05-16 19:42:29 <boxscape> I would say any Haskell functor is an endofunctor because it maps objects in Hask (i.e., types) to other objects in Hask, (i.e., types that have a "Maybe" prefix, for example)
2021-05-16 19:43:22 <boxscape> I should note I'm not exactly an expert in category theory
2021-05-16 19:43:23 × guriya quits (a0ee4bcd@unaffiliated/guriya) (Quit: Connection closed)
2021-05-16 19:43:56 <boxscape> (also for the second i.e., s/i.e./e.g)
2021-05-16 19:43:58 <gedda> so, then for instance kind `* -> *` would be in Hask aswell, as it is a function on types?
2021-05-16 19:44:03 <boxscape> yes
2021-05-16 19:44:12 <boxscape> or wait
2021-05-16 19:44:23 <gedda> such as Maybe
2021-05-16 19:44:26 <gedda> ans not Maybe a
2021-05-16 19:44:28 <gedda> and*
2021-05-16 19:44:31 <boxscape> I actually don't think kinds are in Hask
2021-05-16 19:44:33 <mniip> a haskell type constructor F that has a lawful instance Functor F is an endofunctor Hask -> Haske
2021-05-16 19:44:40 <mniip> Hask *
2021-05-16 19:44:43 <boxscape> but then again... types and kinds are unified
2021-05-16 19:44:49 <mniip> its obejct mapping function is X mapsto F X
2021-05-16 19:44:49 <boxscape> hmmm
2021-05-16 19:44:54 Guest87676 joins (~laudiacay@45.162.228.190)
2021-05-16 19:44:59 × knupfer quits (~Thunderbi@200116b82287f900d8c73651d44749fb.dip.versatel-1u1.de) (Ping timeout: 245 seconds)
2021-05-16 19:45:04 <mniip> its morphism mapping function maps f : X -> Y into fmap f : F X -> F Y
2021-05-16 19:45:15 <boxscape> % undefined :: Maybe (* -> *)
2021-05-16 19:45:15 <yahb> boxscape: ; <interactive>:107:1: error:; * No instance for (Show (* -> *)) arising from a use of `print'; (maybe you haven't applied a function to enough arguments?); * In a stmt of an interactive GHCi command: print it
2021-05-16 19:45:38 <boxscape> gedda I think you're right, it's in Hask
2021-05-16 19:45:51 <mniip> Hask and * are somewhat synonyms
2021-05-16 19:46:01 <mniip> however in other contexts Hask and (->) are synonyms
2021-05-16 19:46:15 <boxscape> gedda the stereotypical exponential objects are more things like `String -> Int` and such
2021-05-16 19:46:20 <mniip> because in a lot of practical haskell code, an (enriched) category is described by its profunctor

All times are in UTC.