Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,803,417 events total
2021-07-25 05:50:04 <davean> for some things one is right, for others the other
2021-07-25 05:50:38 <Cajun> well can Vectors from Data.Vector be used for lazy lists? it doesnt mention strictness on the hackage page
2021-07-25 05:50:51 <davean> no, of course not
2021-07-25 05:51:16 <davean> though it can reference lazy values if you use the boxed ones
2021-07-25 05:51:37 <davean> but vectors themselves could never be lazy, the elements in a boxed vector can be though
2021-07-25 05:52:06 <Cajun> im assuming that even a boxed vector of lazy values still cant be infinite right?
2021-07-25 05:52:18 <davean> No, vectors are specificly finite
2021-07-25 05:52:33 <davean> They have to be, by construction
2021-07-25 05:53:42 <davean> but theres a difference between a lazy list and a list of lazy values
2021-07-25 05:54:32 × nate3 quits (~nate@108-233-125-227.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 258 seconds)
2021-07-25 05:54:34 <davean> vector can only partially match to the second
2021-07-25 05:55:03 <Cajun> what do you mean?
2021-07-25 05:55:31 <davean> so first I want to be clear, theres at least 8 types of Vector
2021-07-25 05:55:40 ubert joins (~Thunderbi@178.165.160.247.wireless.dyn.drei.com)
2021-07-25 05:55:41 <davean> And they've all got different properties
2021-07-25 05:56:13 <davean> but, the one closest in nature to list is the boxed vector
2021-07-25 05:56:53 <davean> It doesn't say anything about strictness, because theres nothing about strictness for it to say
2021-07-25 05:57:08 <davean> if you go over to Data.Vector.Unboxed though, thats a bit of a different story
2021-07-25 05:57:21 <davean> Now for a lazy list vs a list of lazy values
2021-07-25 05:57:32 × ubert quits (~Thunderbi@178.165.160.247.wireless.dyn.drei.com) (Client Quit)
2021-07-25 05:57:46 <davean> theres two parts to a "list" in one way of looking at it, the "spine" which is the list constructors, and the "data" which is the 'a' in [a]
2021-07-25 05:57:48 derelict joins (~derelict@user/derelict)
2021-07-25 05:57:48 ubert joins (~Thunderbi@178.165.160.247.wireless.dyn.drei.com)
2021-07-25 05:57:53 <davean> their laziness is seperate
2021-07-25 05:57:57 <Cajun> lazy list is `_:_` for infinite values vs `_:_:_:_:_:_:_:_:_:....` for list of lazy values yeah?
2021-07-25 05:59:25 <Cajun> well either way, thanks for clearing up my confusion about Vectors :)
2021-07-25 05:59:31 × PinealGlandOptic quits (~PinealGla@37.115.210.35) (Quit: leaving)
2021-07-25 05:59:31 <davean> I hope i helped?
2021-07-25 05:59:42 <Cajun> yeah, i just didnt understand proper use case i guess lol
2021-07-25 05:59:53 <Cajun> always imagined them as a replacement for lists
2021-07-25 06:00:04 <davean> they're not, they can share some use cases but they're not lists
2021-07-25 06:00:28 <davean> cons is O(1) on list, obviously
2021-07-25 06:00:53 <davean> vectors are in a way far more "structured" than list
2021-07-25 06:00:58 <davean> so you get a lot more structural operations
2021-07-25 06:01:07 <davean> Thats REALLY not well defined mind you
2021-07-25 06:01:22 <davean> but lists, for example, you can't tell up front how long they are
2021-07-25 06:01:30 <davean> and they might not even have a definable length
2021-07-25 06:01:38 <davean> their length is a semi-decision problem
2021-07-25 06:01:55 <davean> vectors have an a-prior length by the nature of existing
2021-07-25 06:02:08 × ubert quits (~Thunderbi@178.165.160.247.wireless.dyn.drei.com) (Ping timeout: 255 seconds)
2021-07-25 06:02:10 <davean> so you can talk about the definition for every one of their values
2021-07-25 06:02:27 takuan joins (~takuan@178-116-218-225.access.telenet.be)
2021-07-25 06:02:37 <davean> etc
2021-07-25 06:03:06 <davean> but yah, so about lists
2021-07-25 06:03:27 <davean> [a] is ~ = Cons a RestOfList | EndOfList
2021-07-25 06:03:40 <davean> both a and RestOfList's strictness is seperately defined
2021-07-25 06:03:54 <davean> an infinite list of course must have RestOfList non-strict
2021-07-25 06:04:10 <davean> but the 'a's might always be computed before the next Cons is constructed
2021-07-25 06:04:28 <davean> OTOH, the RestOfLists might all be defined up front, but the 'a's left uncomputed
2021-07-25 06:04:34 <davean> or both might be full computed, or neither
2021-07-25 06:04:43 <davean> a vector, theres onyl one top level constructor
2021-07-25 06:04:56 <davean> so by looking at it at all, the entire spine is done, theres only ever one piece of it
2021-07-25 06:05:30 <davean> a vector, its self, is an atomic entity
2021-07-25 06:06:18 <Cajun> so vector is just a chunk of data vs list being a bunch of "links" which may or may not be computed
2021-07-25 06:06:26 × favonia quits (~favonia@user/favonia) (Ping timeout: 272 seconds)
2021-07-25 06:06:37 <davean> yes
2021-07-25 06:06:46 <davean> The data in a vector might not its self be computed
2021-07-25 06:06:53 <Cajun> but its all there
2021-07-25 06:06:57 <davean> but the vector, if you look at it, must be
2021-07-25 06:07:08 <davean> the definitions are all linked to at least
2021-07-25 06:07:27 <davean> in a block
2021-07-25 06:07:47 <davean> you can't just "replace" the first element in a vector like you can in a list for example for that reason
2021-07-25 06:08:23 favonia joins (~favonia@user/favonia)
2021-07-25 06:08:35 <davean> (I say just, because with the correct conditions you can change it, with a mutable vector in the correct context for example, but now the old version no longer exists - where as with the list that isn't the case)
2021-07-25 06:09:18 <davean> Theres a lot of places lists are miss-used instead of vectors, because lists are closer at hand, but they're fundimentally unrelated datastructures
2021-07-25 06:09:51 <Cajun> ah that makes a lot of sense, i guess that makes pattern matching on them just a foolish idea, considering a new Vector must be made for each recurse, yeah?
2021-07-25 06:09:53 <davean> with entirely different properties
2021-07-25 06:10:15 <davean> well, ... sorta, I mean you can pattern match and pass down an index for example
2021-07-25 06:10:25 <davean> go i v | h <- v ! i = ...
2021-07-25 06:10:46 <davean> right? Like you can walk down it, and look at each value seperately, but why aren't you folding then?
2021-07-25 06:11:03 <davean> go on the tail is of course go (i+1) v
2021-07-25 06:11:08 anandprabhu joins (~anandprab@94.202.243.198)
2021-07-25 06:11:24 <davean> But we've BASICLY just implimented a fold
2021-07-25 06:11:28 <Cajun> well assuming the function constructs a new vector of some kind. im guessing im just using them wrong (as a list replacement)
2021-07-25 06:11:53 <davean> well, depends on what new construction you're making
2021-07-25 06:12:01 <davean> if the construction is of the same time, thats a map or a scan
2021-07-25 06:12:31 <davean> if the construciton is of a known size, then thats a generate with the passed function capturing the origional list
2021-07-25 06:12:41 <davean> if you don't know the length, you're not ready to create a vector yet!
2021-07-25 06:13:05 <davean> and then you'd be using it wrong, or at least you'd have a LOT of book keeping to do to do a good job of using it well (fusion can take care of most of that automaticly for you)
2021-07-25 06:14:19 × wei2912 quits (~wei2912@112.199.250.21) (Quit: Lost terminal)
2021-07-25 06:14:51 <davean> Also, I am sorry to anyone watching for my abuse of guards here.
2021-07-25 06:15:13 <davean> For the record I don't actually support that style, it just works and is concies and isn't Viewpatterns and I was making a point
2021-07-25 06:15:30 <Cajun> yeah it helps to make your point more clear lol
2021-07-25 06:15:34 wei2912 joins (~wei2912@112.199.250.21)
2021-07-25 06:16:28 <davean> Cajun: I do expect you should stare at fold, map, scan a bit and consider if they're the actual structure you're implimenting
2021-07-25 06:17:00 <davean> data Vector a = Vector {-# UNPACK #-} !Int {-# UNPACK #-} !Int {-# UNPACK #-} !(Array a)
2021-07-25 06:17:10 <davean> BTW if you were interested in what Vector (at least the boxed variant) is
2021-07-25 06:17:12 × Lord_of_Life quits (~Lord@user/lord-of-life/x-2819915) (Ping timeout: 272 seconds)
2021-07-25 06:17:33 Lord_of_Life joins (~Lord@user/lord-of-life/x-2819915)
2021-07-25 06:17:59 <davean> so whats tail? tail (Vector o s a) = Vector (o+1) (s-1) a
2021-07-25 06:18:14 machinedgod joins (~machinedg@s72-38-105-27.static.comm.cgocable.net)
2021-07-25 06:18:16 × lavaman quits (~lavaman@98.38.249.169) (Remote host closed the connection)
2021-07-25 06:18:23 <davean> I mean with a bunch of bounds checks and stuff
2021-07-25 06:18:34 × wei2912 quits (~wei2912@112.199.250.21) (Client Quit)
2021-07-25 06:18:40 <davean> I'm of course leaving out al the important code :)
2021-07-25 06:19:08 <Cajun> yeah at one point i realized what im essentially doing is reinventing map. though one time i hit the wall was when i was trying to make a function like `chunksOf` from Data.List.Split, and it doesnt seem like a map, fold, or scan would work well there
2021-07-25 06:19:52 wei2912 joins (~wei2912@112.199.250.21)
2021-07-25 06:20:22 <davean> sure, that'll work, you can do that as a fold for example just fine
2021-07-25 06:20:29 <c_wraith> that's more of an unfold
2021-07-25 06:20:56 <davean> I mean yah it is, but you can do it

All times are in UTC.