Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→
Page 1 .. 232 233 234 235 236 237 238 239 240 241 242 .. 5022
502,152 events total
2020-09-26 18:18:15 <tomsmeding> the overflow problem can be solved by either going to Integer or to Double, but people won't expect that
2020-09-26 18:18:24 <tomsmeding> since the algorithm can overflow before the correct answer would
2020-09-26 18:18:32 <dsal> Or Scientific!
2020-09-26 18:18:44 <fluturel> ski: is !! defined recursively with pattern matching as well? That would make sense, but i thought it would be a built-in or something, written directly in the target language in the compiler to make it faster. I may be spewing nonsense, but it is what i thought
2020-09-26 18:19:09 <ski> fluturel : yes
2020-09-26 18:19:13 <ski> it's not built-in
2020-09-26 18:19:25 <ski> just a library operation, defined in Haskell
2020-09-26 18:19:26 <dsal> @fluturel There's a source link in the doc pages. !! is a bit fancy: https://hackage.haskell.org/package/base-4.14.0.0/docs/src/GHC.List.html#%21%21
2020-09-26 18:19:26 <lambdabot> Unknown command, try @list
2020-09-26 18:19:26 <dolio> I've never needed binomial coefficients in my programs in like 15 years of writing Haskell.
2020-09-26 18:19:30 <dolio> Maybe that's why it's not in base.
2020-09-26 18:19:32 <dsal> @src (!!)
2020-09-26 18:19:32 <lambdabot> xs !! n | n < 0 = undefined
2020-09-26 18:19:32 <lambdabot> [] !! _ = undefined
2020-09-26 18:19:32 <lambdabot> (x:_) !! 0 = x
2020-09-26 18:19:32 <lambdabot> (_:xs) !! n = xs !! (n-1)
2020-09-26 18:19:39 × geekosaur quits (42d52102@66.213.33.2) (Ping timeout: 245 seconds)
2020-09-26 18:19:49 <dsal> lambdabot's @src will show you a simple, idealized implementation, but not necessarily what GHC will do.
2020-09-26 18:20:58 hackage config-value 0.8 - Simple, layout-based value language similar to YAML or JSON https://hackage.haskell.org/package/config-value-0.8 (EricMertens)
2020-09-26 18:21:22 <fluturel> dsal: i'm having a bit of trouble with the src there, but i get the gist
2020-09-26 18:21:53 <dsal> foldr has a few magic bits that takes intuition a bit of time to catch up with.
2020-09-26 18:22:18 <fluturel> i didn't get to foldr yet
2020-09-26 18:22:22 <dsal> That's why @src shows you a trivial, functionally equivalent version. :)
2020-09-26 18:22:34 <ski> `| k > n = undefined' ought to be `| k > n = 0', arguably
2020-09-26 18:22:45 <dsal> I use foldr a *lot*, but foldr + laziness means you can fold infinite lists meaningfully.
2020-09-26 18:22:47 <fluturel> @src foldr
2020-09-26 18:22:47 <lambdabot> foldr f z [] = z
2020-09-26 18:22:47 <lambdabot> foldr f z (x:xs) = f x (foldr f z xs)
2020-09-26 18:23:27 <dsal> foldr is like, the default catamorphism. If you have a bunch of stuff and you want some kind of potentially smaller transformation of it, that's foldr.
2020-09-26 18:23:32 <oats> I forget, is foldl the one that's discouraged, or foldr
2020-09-26 18:23:45 <dsal> The problem with *that* foldr implementation is that it works in far fewer cases than the real one.
2020-09-26 18:23:48 <c_wraith> generally you want foldl' instead of foldl
2020-09-26 18:23:51 <dsal> oats: foldl should basically never be used.
2020-09-26 18:24:00 <oats> that's what I thought
2020-09-26 18:24:00 <fluturel> dsal: why?
2020-09-26 18:24:11 <dsal> fluturel: why which?
2020-09-26 18:24:26 <fluturel> dsal: why should foldl nver be used?
2020-09-26 18:24:28 hackage config-schema 1.2.1.0 - Schema definitions for the config-value package https://hackage.haskell.org/package/config-schema-1.2.1.0 (EricMertens)
2020-09-26 18:24:49 <dsal> fluturel: Oh, just dumb behavior. foldl' is what you want if you think you want foldl most of the time. foldr is the default, though.
2020-09-26 18:25:06 <oats> https://github.com/hasura/graphql-engine/pull/2933#discussion_r328821960
2020-09-26 18:25:10 <dsal> foldl' is strict on the accumulator. foldl has to build up a giangantic thunk before doing anything.
2020-09-26 18:25:50 <oats> tldr, foldl is too lazy and leaks memory
2020-09-26 18:25:59 <fluturel> foldr is kind of like reduce in CL?
2020-09-26 18:26:23 <dsal> fold, foldl, foldr, etc... are all that type of catamorphism, yeah.
2020-09-26 18:26:25 × thir quits (~thir@p200300f27f0fc60094e773283d7bf825.dip0.t-ipconnect.de) (Remote host closed the connection)
2020-09-26 18:26:36 <dsal> :t foldr -- the real foldr works on a lot more than lists, though.
2020-09-26 18:26:36 HarveyPwca joins (~HarveyPwc@2601:246:c180:a570:29df:3b00:ad0e:3a06)
2020-09-26 18:26:37 <lambdabot> Foldable t => (a -> b -> b) -> b -> t a -> b
2020-09-26 18:27:06 thir joins (~thir@p200300f27f0fc60094e773283d7bf825.dip0.t-ipconnect.de)
2020-09-26 18:27:10 <fluturel> so anything that belongs to the Foldable typeclass
2020-09-26 18:27:18 <dsal> "has an instance of" yeah
2020-09-26 18:27:29 <oats> “When the accumulation function is strict, use foldl' to consume the list in constant space, since the whole list is going to have to be traversed, anyway.
2020-09-26 18:27:38 <oats> When the accumulation function is lazy in its second argument, use foldr to do work incrementally to improve streaming and work-saving.
2020-09-26 18:27:40 <dsal> You can make a thing, make your thing foldable, and a *lot* of functionality comes about for free.
2020-09-26 18:27:40 <oats>
2020-09-26 18:28:14 × raehik quits (~raehik@cpc96984-rdng25-2-0-cust109.15-3.cable.virginm.net) (Ping timeout: 258 seconds)
2020-09-26 18:28:15 <dsal> :t sum -- e.g., you get stuff like this for free
2020-09-26 18:28:17 <lambdabot> (Foldable t, Num a) => t a -> a
2020-09-26 18:29:10 <fluturel> what is "t a"? Why is there no `->` inbetween?
2020-09-26 18:29:27 hackage hookup 0.5 - Abstraction over creating network connections with SOCKS5 and TLS https://hackage.haskell.org/package/hookup-0.5 (EricMertens)
2020-09-26 18:30:00 <fluturel> sorry for my very beginner questions :)
2020-09-26 18:30:39 <{abby}> fluturel: `t a` is the type constructor `t` applied to the type `a`; if you set (for example) t = Maybe then you get `Maybe a`, for t = [] (lists) you get `[] a` (commonly spelled `[a]`), etc
2020-09-26 18:31:25 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 240 seconds)
2020-09-26 18:31:32 <dsal> You can colloquially read that as a "Foldable (thing of) Num" if you're being extra lazy.
2020-09-26 18:31:45 rcdilorenzo joins (~rcdiloren@cpe-76-182-87-188.nc.res.rr.com)
2020-09-26 18:31:47 <fluturel> so t is a container of some sorts (or can be, for a type a)
2020-09-26 18:31:47 × thir quits (~thir@p200300f27f0fc60094e773283d7bf825.dip0.t-ipconnect.de) (Ping timeout: 260 seconds)
2020-09-26 18:32:09 justan0theruser joins (~justanoth@unaffiliated/justanotheruser)
2020-09-26 18:32:11 <ski> fluturel : yes. `t' specifies some kind of "container", and `a' the "element type", there
2020-09-26 18:32:21 <dsal> "Container" is often a lazy way to look at some of these things. It doesn't need to be a container per se, just Foldable.
2020-09-26 18:33:08 <ski> fluturel : and no worry, beginner questions are welcome in here
2020-09-26 18:33:58 × fresheyeball quits (~isaac@c-71-237-105-37.hsd1.co.comcast.net) (Quit: WeeChat 2.7.1)
2020-09-26 18:34:07 × justanotheruser quits (~justanoth@unaffiliated/justanotheruser) (Ping timeout: 240 seconds)
2020-09-26 18:34:14 <{abby}> dsal: I'd agree if we were talking about Monad & co but I honestly don't see a problem with referring to instances of Foldable as "containers"
2020-09-26 18:34:30 <fraktor> What is a foldable that is not also a container?
2020-09-26 18:34:48 <dsal> I can make a dumb obligatory example, but it's kind of pointless.
2020-09-26 18:34:49 <c_wraith> yeah... unlike many things, Foldable must actually contain (0 or more) values of a particular type
2020-09-26 18:34:59 × _vaibhavingale_ quits (~Adium@203.188.228.27) (Ping timeout: 240 seconds)
2020-09-26 18:35:00 <dsal> If it's Foldable, it's probably containing things.
2020-09-26 18:35:05 <ski> (`Const c' is an "always empty" container type)
2020-09-26 18:36:05 adam_wespiser joins (~adam_wesp@209.6.42.110)
2020-09-26 18:38:28 <ski> fluturel : in the type `[Int]', which is more uniformly spelled as `[] Int', you can read `[]' as "list of". it specifies the type of container. but you can't have e.g. `foo :: []'. `foo' can't have type "list of", it must be a list of something (some type to use as element type)
2020-09-26 18:39:40 <ski> you could say that `[]', and other similar things, like `Maybe',`Either',`Map',`IO' are "incomplete types", requires one to specify some more type(s) after it, to get a concrete type, that you could use as the type of a value (perhaps an input value to, or an output value from, a function)
2020-09-26 18:40:31 <ski> one could also call these "parameterized types", or "type functions" (not to be confused with "function types", which are types of the shape `.. -> ..', like e.g. `[a] -> Int' or `Int -> [a] -> [a]')
2020-09-26 18:41:00 × adam_wespiser quits (~adam_wesp@209.6.42.110) (Ping timeout: 272 seconds)
2020-09-26 18:41:24 × v_m_v quits (~vm_v@2a02:aa12:3200:6480:f507:71a:9334:3099) (Remote host closed the connection)
2020-09-26 18:41:29 <ski> `[]' is like a function that consumes not values, but types (ordinary, concrete types, not type functions). so, if you pass it the type `Int', you get back the type of lists of `Int's
2020-09-26 18:44:52 <monochrom> It is useful to first look at "Maybe Int" syntactically and break it into the Maybe-ness and the Int-ness.
2020-09-26 18:45:17 oisdk joins (~oisdk@2001:bb6:3329:d100:4c4c:f42f:20c9:6844)
2020-09-26 18:45:19 <monochrom> And then to also find in in horror that "[] Int" is legal syntax, too. That will put things in perspectives.
2020-09-26 18:46:21 <dsal> Why can't I use MayIntBe ?
2020-09-26 18:46:31 dsal is angered by haskell's inconsistent syntax
2020-09-26 18:46:36 <monochrom> Haskell takes seriously the idea of isolating out the Maybe-ness, the []-ness. Other languages don't, and that's where they run into a severe limitation.
2020-09-26 18:47:12 <monochrom> Oh, for general mixfix syntax, please refer to Agda. >:)
2020-09-26 18:47:48 oab joins (~oab@214.92-220-221.customer.lyse.net)
2020-09-26 18:48:21 <monochrom> User-definable mixfix could be a nice addition the next time the Haskell report is updated.
2020-09-26 18:48:31 <dolio> Agda doesn't let you arbitrarily divide tokens that weren't defined that way, though.
2020-09-26 18:48:41 mu_ joins (~mu@unaffiliated/mu)
2020-09-26 18:49:00 <dolio> Mixfix design is a huge mess of tradeoffs, too.
2020-09-26 18:49:02 <monochrom> Yeah, not MayIntBe per se, but perhaps ^Int$

All times are in UTC.