Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→
Page 1 .. 229 230 231 232 233 234 235 236 237 238 239 .. 5022
502,152 events total
2020-09-26 16:31:12 mu__ joins (~mu@unaffiliated/mu)
2020-09-26 16:32:12 × thir quits (~thir@p200300f27f0fc60094e773283d7bf825.dip0.t-ipconnect.de) (Ping timeout: 260 seconds)
2020-09-26 16:32:13 fluturel joins (~fluturel@82.137.14.51)
2020-09-26 16:32:56 <fluturel> i have a small question regarding a small piece of code i wrote
2020-09-26 16:33:06 geekosaur joins (42d52102@66.213.33.2)
2020-09-26 16:33:19 <fluturel> I am trying to write a zip function
2020-09-26 16:33:38 <fluturel> but for some reason it doesn't seem to want to work with infinite lists
2020-09-26 16:33:56 <ski> did you use an accumulator ?
2020-09-26 16:34:07 × sand_dull quits (~theuser@185.217.69.182) (Ping timeout: 240 seconds)
2020-09-26 16:34:23 <fluturel> This is my version with list comprehension: zip' xs ys = [(xs !! i, ys !! i) | i <- [0..(min (length xs) (length ys))-1]]
2020-09-26 16:34:39 <fluturel> ski: how do you mean?
2020-09-26 16:34:51 × mu__ quits (~mu@unaffiliated/mu) (Client Quit)
2020-09-26 16:35:06 <fluturel> my suspicion is it doesn't work becuase of the min function
2020-09-26 16:35:12 <ski> ok. yea `length' won't terminate on infinite lists
2020-09-26 16:35:26 <ski> > [0 .. length [0 ..] - 1]
2020-09-26 16:35:30 × dhil quits (~dhil@11.29.39.217.dyn.plus.net) (Ping timeout: 256 seconds)
2020-09-26 16:35:33 <lambdabot> mueval-core: Time limit exceeded
2020-09-26 16:35:37 × mmohammadi9812 quits (~mmohammad@5.238.165.34) (Ping timeout: 264 seconds)
2020-09-26 16:35:42 × mnrmnaughmnrgle quits (~mnrmnaugh@unaffiliated/mnrmnaugh) (Ping timeout: 260 seconds)
2020-09-26 16:35:52 <fluturel> yeah, that makes sense and i figured that much
2020-09-26 16:36:03 <fluturel> is there any way to check if a list is infinite?
2020-09-26 16:36:04 <ski> so the problem is that you're using `length'
2020-09-26 16:36:06 <ski> no
2020-09-26 16:36:29 <ski> you can only observe finitely many elements of a list, in finite time
2020-09-26 16:37:01 <ski> so, if you've seen a thousand elements, then you know the list has at least that many elements. might have no more, or one or ten more. or might be infinite
2020-09-26 16:37:54 mmohammadi9812 joins (~mmohammad@188.210.108.97)
2020-09-26 16:37:56 <ski> to gracefully handle infinite lists, make sure that your computation is "incremental", or productive, will produce some part(s) of the output, before having seen the end of the input list(s)
2020-09-26 16:38:44 <ski> `length' is not incremental. it won't produce an answer, until it sees the end of the list. and since an infinite list has no end, it will never produce an answer, for such
2020-09-26 16:39:26 <fluturel> so i iterate through the elements, form the tuples, and check if the next i is valid for both lists. If it isn't for one of them, that's all i need to know
2020-09-26 16:40:12 <ski> yea, i suppose you could do that
2020-09-26 16:40:37 <fluturel> what aabout the accumulator you mentioned?
2020-09-26 16:40:44 <ski> another approach is to not bother with indices at all, just to pattern-match on the lists
2020-09-26 16:41:22 × toorevitimirp quits (~tooreviti@117.182.182.201) (Read error: Connection reset by peer)
2020-09-26 16:41:25 <fluturel> i haven't learned pattern-matching yet, so i don't know the syntax or anything
2020-09-26 16:41:55 <ski> well .. sometimes people write "loops" like this, using an accumulator. but that doesn't really work, for infinite lists. so, i was thinking that maybe you were using an accumulator, and that that was why your function didn't work on infinite lists
2020-09-26 16:42:08 <ski> ok
2020-09-26 16:42:33 <ski> if you can check whether an index is a valid index in a list, i think you should be able to do it that way, as well
2020-09-26 16:42:48 Izeau joins (~Izeau@2001:41d0:8:c493::)
2020-09-26 16:43:12 <ski> (and you would have to check that, without calling `length' on the list)
2020-09-26 16:43:23 <ski> hm
2020-09-26 16:43:39 snakemasterflex joins (~snakemast@213.100.206.23)
2020-09-26 16:44:25 <ski> i think i see one way you could do it .. using a library function, from the `Prelude'
2020-09-26 16:44:59 <ski> (alternatively, you could try diving into pattern-matching, at this point)
2020-09-26 16:45:00 <fluturel> ok, shoot
2020-09-26 16:45:22 <ski> consider the `!!' operator
2020-09-26 16:45:25 <ski> @type (!!)
2020-09-26 16:45:27 <lambdabot> [a] -> Int -> a
2020-09-26 16:45:49 <ski> the problem here is that this assumes that the given index is already valid
2020-09-26 16:46:00 <ski> > [2,3,5,7] !! 23
2020-09-26 16:46:01 mnrmnaughmnrgle joins (~mnrmnaugh@unaffiliated/mnrmnaugh)
2020-09-26 16:46:04 <lambdabot> *Exception: Prelude.!!: index too large
2020-09-26 16:46:15 <fluturel> yeah, exactly
2020-09-26 16:46:29 <ski> so, you'd like to be able to detect whether an index is valid (without calling `length')
2020-09-26 16:46:39 <ski> do you know the `Maybe' data type ?
2020-09-26 16:47:19 <fluturel> heard about it. It's something like: maybe it's an int, maybe its Nothing
2020-09-26 16:47:25 <ski> yes
2020-09-26 16:47:36 <ski> it's something which you could possibly use here
2020-09-26 16:47:57 <ski> if you could define an operator, say `!!?', with a type signature
2020-09-26 16:48:05 <ski> (!!?) :: [a] -> Int -> Maybe a
2020-09-26 16:48:44 <ski> so that it looks up the value at the given index, if the index is valid, and otherwise tells the caller that there was no value to give back
2020-09-26 16:48:55 <ski> that could be one way
2020-09-26 16:49:14 <fluturel> but that would mean i need to catch the exception if it doesn't find anything there, right?
2020-09-26 16:49:20 <ski> then, after calling that, it'd tell you whether it succeeded in looking up, or not
2020-09-26 16:49:23 <ski> well
2020-09-26 16:49:39 <ski> `!!' gives an exception, in case the index is not valid
2020-09-26 16:49:45 Izeau parts (~Izeau@2001:41d0:8:c493::) ()
2020-09-26 16:49:47 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 240 seconds)
2020-09-26 16:50:02 <fluturel> yeah
2020-09-26 16:50:09 <ski> however, the point here was that `!!?' would not give an exception then. but rather return an "error code", so to speak
2020-09-26 16:50:18 × fxg quits (~fxg@unaffiliated/fxg) (Ping timeout: 260 seconds)
2020-09-26 16:50:33 <ski> so, you wouldn't need any exception catching, just to check the result whether there's an `a' element there or not
2020-09-26 16:50:45 <fluturel> yeah, no, i understand that. I am querstioning what to do while implementing !!?
2020-09-26 16:51:07 <ski> anyway, you'd still need to define `!!?', somehow (possibly using a `Prelude' function, as i hinted at)
2020-09-26 16:51:27 <ski> and then, you'd need to figure out how to inspect the result of calling `!!?', in your `zip' version
2020-09-26 16:52:06 <ski> the alternative here, would be to directly call that `Prelude' function from `zip', skipping `!!?' altogether (so, skipping having to deal with `Maybe')
2020-09-26 16:52:21 <ski> but then you'd be dealing with more details, at the same time, perhaps
2020-09-26 16:52:42 <fluturel> this seems like way above my paygrade for now, but i will give it a shot, although i barely learned the basics in haskell by now
2020-09-26 16:52:45 × raehik quits (~raehik@cpc96984-rdng25-2-0-cust109.15-3.cable.virginm.net) (Ping timeout: 240 seconds)
2020-09-26 16:52:52 <fluturel> I will see what i can ddo
2020-09-26 16:53:17 × snakemasterflex quits (~snakemast@213.100.206.23) (Ping timeout: 256 seconds)
2020-09-26 16:53:25 stef204 joins (~stef204@unaffiliated/stef-204/x-384198)
2020-09-26 16:53:30 elliott_ joins (~elliott@pool-100-36-54-163.washdc.fios.verizon.net)
2020-09-26 16:53:49 <ski> to work with `Maybe' values, you could use `Nothing',`Just',`isJust',`fromJust'
2020-09-26 16:54:43 <ski> fluturel : would you like a hint for how you could check if an index is valid ?
2020-09-26 16:55:01 retropikzel_ joins (~Retropikz@dyvyf3fs8gw7zbnhkmk4y-4.rev.dnainternet.fi)
2020-09-26 16:55:09 <fluturel> when declarinf functions i saw you can write something like func :: Int -> Int -> Int. Which is the return type? The last one?
2020-09-26 16:55:20 <ski> yes, the last one
2020-09-26 16:55:27 raehik joins (~raehik@cpc96984-rdng25-2-0-cust109.15-3.cable.virginm.net)
2020-09-26 16:55:49 <fluturel> I think I will do my research on that one, i need to get familiar with the docs. If I can't, i will come back here
2020-09-26 16:55:56 <fluturel> ok, thank you
2020-09-26 16:56:00 ski nods
2020-09-26 16:56:07 × knupfer quits (~Thunderbi@200116b82c2b4e000cf1902bacfcade4.dip.versatel-1u1.de) (Ping timeout: 260 seconds)
2020-09-26 16:56:19 <fluturel> how do you do that?
2020-09-26 16:56:25 <ski> hm, do what ?
2020-09-26 16:56:25 <fluturel> The nods thing
2020-09-26 16:56:31 <ski> /me nods
2020-09-26 16:56:48 fluturel looks frightened at the documentation
2020-09-26 16:56:54 <fluturel> Awesome
2020-09-26 16:57:06 <ski> np
2020-09-26 16:58:46 isovector1 joins (~isovector@172.103.216.166)

All times are in UTC.