Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,804,011 events total
2021-08-06 22:14:41 × machinedgod quits (~machinedg@135-23-192-217.cpe.pppoe.ca) (Ping timeout: 258 seconds)
2021-08-06 22:14:43 roboguy_ joins (~roboguy_@2605:a601:afe7:9f00:6574:78ba:36fc:f777)
2021-08-06 22:18:54 × lbseale quits (~lbseale@user/ep1ctetus) (Quit: Leaving)
2021-08-06 22:20:17 Codaraxis_ joins (~Codaraxis@user/codaraxis)
2021-08-06 22:22:18 × Codaraxis_ quits (~Codaraxis@user/codaraxis) (Client Quit)
2021-08-06 22:23:14 × ukari quits (~ukari@user/ukari) (Remote host closed the connection)
2021-08-06 22:23:46 ukari joins (~ukari@user/ukari)
2021-08-06 22:23:54 × Codaraxis__ quits (~Codaraxis@user/codaraxis) (Ping timeout: 240 seconds)
2021-08-06 22:25:25 _73 joins (~user@pool-96-252-123-136.bstnma.fios.verizon.net)
2021-08-06 22:27:10 <_73> Would a haskell vector with 8 Word8's use just as much memory as a vector with 2 Word32's? I am trying to understand the difference between a vector and an array in C.
2021-08-06 22:29:43 euouae joins (~euouae@user/euouae)
2021-08-06 22:29:56 <euouae> hello I’m making a simple hangman game of guessing the word
2021-08-06 22:30:26 × shapr quits (~user@pool-108-28-144-11.washdc.fios.verizon.net) (Ping timeout: 252 seconds)
2021-08-06 22:30:49 <euouae> I wrote a type Game containing a type State which among other things has a list of Hide Char which may be hidden or visible
2021-08-06 22:31:44 <euouae> and the usual update functions and such, had trouble naming variables and I sense some duplication in code maybe. Is that a good approach in general ?
2021-08-06 22:32:04 <dsal> euouae: It'd be easier to see the code instead of imagining your concern. :)
2021-08-06 22:32:18 <euouae> Hmm alright give me 5
2021-08-06 22:33:23 <dsal> `data Game = Game { _phrase :: String, shown _visible :: Set Char }` would seem to do it all.
2021-08-06 22:33:39 <euouae> Yeah but then you’re delegating a lot to algorithms
2021-08-06 22:33:53 <dsal> Ah, the eternal battle between data structures and algorithms.
2021-08-06 22:33:56 <euouae> whereas you can also have more duplication of info in the state
2021-08-06 22:34:05 <euouae> Ahah ok
2021-08-06 22:34:34 <euouae> Actually need to make a call I’ll post code in 10
2021-08-06 22:34:37 <dsal> Duplicating data is useful when your algorithm is slow.
2021-08-06 22:35:28 × dispater quits (~dispater@user/brprice) (Quit: ZNC 1.8.1 - https://znc.in)
2021-08-06 22:35:58 <monochrom> The other technique for efficiency is structured data.
2021-08-06 22:36:20 PinealGlandOptic joins (~PinealGla@37.115.210.35)
2021-08-06 22:37:14 dispater joins (~dispater@user/brprice)
2021-08-06 22:37:22 <geekosaur> _73, the smallest value ghc natively supports is a machine word, so a vector of 8 Word8s takes up the same space as a vector of Word64s on a 64-bit platform
2021-08-06 22:37:37 <geekosaur> this is a GHC limitation, not a Vector limitation
2021-08-06 22:38:02 <geekosaur> that said, there are variants of Vector which go behind GHC's back and support packed vectors
2021-08-06 22:39:03 × euouae quits (~euouae@user/euouae) (Quit: Ping timeout (120 seconds))
2021-08-06 22:39:11 <_73> geekosaur: are you saying that in the end Word8's take up 64 bits on my 64-bit computer?
2021-08-06 22:39:20 <geekosaur> yes
2021-08-06 22:39:36 × vysn quits (~vysn@user/vysn) (Remote host closed the connection)
2021-08-06 22:40:09 <geekosaur> ghc 9.2 is taking the first steps in changing this but I believe it still requires word-size alignment right now,, so things won't change there
2021-08-06 22:40:21 <_73> oh ok. I need to look into packed vectors then.
2021-08-06 22:40:53 <geekosaur> I *think* Nyou want Storable Vector
2021-08-06 22:42:37 roboguy__ joins (~roboguy_@2605:a601:afe7:9f00:cdb7:2350:8543:710d)
2021-08-06 22:42:40 <_73> So if I have a length 8 `Data.Vector.Storable.Vector Word8` it will truly be 64 bits?
2021-08-06 22:43:50 <geekosaur> I said "I *think*". I haven't looked closely and there's several vector variants I haven't used yet., including both storable and unpacked vectors
2021-08-06 22:44:00 <geekosaur> someone else here may know more
2021-08-06 22:44:27 <_73> ok thanks for this.
2021-08-06 22:45:01 robogu___ joins (~roboguy_@2605:a601:afe7:9f00:49e1:58f7:bf60:9b3c)
2021-08-06 22:46:10 × sim590 quits (~simon@modemcable090.207-203-24.mc.videotron.ca) (Ping timeout: 240 seconds)
2021-08-06 22:46:24 × roboguy_ quits (~roboguy_@2605:a601:afe7:9f00:6574:78ba:36fc:f777) (Ping timeout: 272 seconds)
2021-08-06 22:47:11 <geekosaur> meanwhile it's even worse than you think because normal Vectors are also storing a worde-sized constructor tag even though it's always 0 for Word8
2021-08-06 22:47:46 × roboguy__ quits (~roboguy_@2605:a601:afe7:9f00:cdb7:2350:8543:710d) (Ping timeout: 240 seconds)
2021-08-06 22:48:32 <geekosaur> so 8 Word8s take up 32 words or 256 bytes
2021-08-06 22:49:18 × Cajun quits (~Cajun@user/cajun) (Quit: Client closed)
2021-08-06 22:49:19 roboguy_ joins (~roboguy_@2605:a601:afe7:9f00:38b9:e9e9:c93:b099)
2021-08-06 22:49:43 <nshepperd> unboxed and storable vectors should both be efficient i think
2021-08-06 22:51:00 <_73> ok this was the kind of thing I was worried about and why I asked the question in the first place. Im looking for the closest thing I can get to an immutable C array.
2021-08-06 22:51:01 <nshepperd> the difference is that storable uses pinned memory that you can use with the FFI
2021-08-06 22:51:33 <geekosaur> that'd be (and be the point of) Storable
2021-08-06 22:52:38 × robogu___ quits (~roboguy_@2605:a601:afe7:9f00:49e1:58f7:bf60:9b3c) (Ping timeout: 258 seconds)
2021-08-06 22:54:09 <monochrom> Some of the very primitive low-level bytearray types in GHC.* would be the only thing remotely close to a C array, mutable or immutable.
2021-08-06 22:54:16 <nshepperd> unboxed uses https://hackage.haskell.org/package/primitive-0.7.2.0/docs/Data-Primitive-ByteArray.html for storage
2021-08-06 22:54:52 <monochrom> Meaning, you don't spend 8 bytes to store size, you don't spend 8 bytes to store one level of indirection.
2021-08-06 22:54:53 × lavaman quits (~lavaman@98.38.249.169) (Remote host closed the connection)
2021-08-06 22:56:14 <monochrom> Of an 8-element array, the Data.Vector.* solutions of "8 bytes for size, 8 bytes for offset index, 8 bytes for pointer to the actual bytes" is very significant.
2021-08-06 22:56:49 <monochrom> And oh 8 bytes for the data constructor itself, too.
2021-08-06 22:59:04 × nvmd quits (~nvmd@user/nvmd) (Quit: Later, nerds.)
2021-08-06 23:00:11 sim590 joins (~simon@modemcable090.207-203-24.mc.videotron.ca)
2021-08-06 23:00:37 <monochrom> And I have unfavourable opinions on optimizing merely 8 elements, too.
2021-08-06 23:02:01 <monochrom> If you have a million instances of these 8-element arrays, the container that contains those 1 million pointers would be just as worrisome.
2021-08-06 23:02:48 <monochrom> If your question is a proxy question for "I really have 1 array of 1 million elements", that's very easy to whip up some code to empirically measure.
2021-08-06 23:02:50 × Pickchea quits (~private@user/pickchea) (Quit: Leaving)
2021-08-06 23:03:40 <_73> I really have 1 array of 1 million elements. Each element is a Word8.
2021-08-06 23:03:50 lavaman joins (~lavaman@98.38.249.169)
2021-08-06 23:04:25 <dsal> That's very verbose.
2021-08-06 23:07:55 <_73> I know. I have been at this weeks. I am making a Y86-64 implementation (simple version of X86-64), and the 2 main goals of the project are purity, and accuracy to a true Y86-64 computer. I still can't think of a better way to represent memory.
2021-08-06 23:08:10 euouae joins (~euouae@user/euouae)
2021-08-06 23:08:21 × lavaman quits (~lavaman@98.38.249.169) (Ping timeout: 258 seconds)
2021-08-06 23:08:24 <euouae> https://termbin.com/tdaw -- here is my Hangman lib
2021-08-06 23:08:53 <euouae> with confusing logic and overengineering
2021-08-06 23:09:00 <euouae> and if possible, underengineering too
2021-08-06 23:09:26 × Melantha quits (~pyon@user/pyon) (Quit: WeeChat 3.2)
2021-08-06 23:10:42 <dsal> Yeah, I don't really like that `[CharStatus]` thing because once a character is guessed, it needs to be revealed (unless you require them to guess the same thing multiple times).
2021-08-06 23:11:00 <dsal> I was thinking something more like this:
2021-08-06 23:11:13 <dsal> > let st = ("This is a string", ['a', 's', 't', ' ']); printG (s, ls) = map (\x -> bool '_' x (x `elem` ls)) s in printG st
2021-08-06 23:11:15 <lambdabot> "___s _s a st____"
2021-08-06 23:11:30 <euouae> yeah but these are haskell tricks you're doing
2021-08-06 23:11:35 <euouae> little tricks for the pros
2021-08-06 23:11:40 <dsal> heh. Did I do a trick?
2021-08-06 23:12:11 <euouae> I didn't know of 'bool'
2021-08-06 23:12:22 <dsal> Oh.
2021-08-06 23:12:29 <dsal> That's just a function.
2021-08-06 23:12:34 <dsal> > let st = ("This is a string", ['a', 's', 't', ' ']); printG (s, ls) = map (\x -> if x `elem` ls then x else '_') s in printG st
2021-08-06 23:12:36 <lambdabot> "___s _s a st____"
2021-08-06 23:12:58 <c_wraith> at least bool is in base now. It was awkward not having a function that did that without adding packages
2021-08-06 23:13:12 <dsal> It's similar to yours, I just separated the string being guessed from the list of chars. I also didn't do a case conversion.
2021-08-06 23:13:30 <dsal> > let st = ("This is a string", ['a', 's', 't', ' ']); printG (s, ls) = map (\x -> bool '_' x (toLower x `elem` ls)) s in printG st
2021-08-06 23:13:32 <lambdabot> "T__s _s a st____"
2021-08-06 23:14:06 <dsal> But the idea is you've got the one thing that's the input being guessed, and you've got the list of guesses. You can track how many guesses there were and you can apply that list of guesses when forming the string.
2021-08-06 23:14:24 <euouae> It's not that I couldnt' write this myself
2021-08-06 23:14:34 <euouae> I guess I'm more struggling with the rest of it, the state of the game and updating it, reading input etc
2021-08-06 23:16:16 <dsal> Sure, I'm suggesting reducing state a bit. With the data structure I've got there, you've won when all the letters in your word are in the list. A guess adds a word to that list and does that evaluation.
2021-08-06 23:16:44 <euouae> Yeh you've won when s == printG s
2021-08-06 23:17:06 <dsal> You can compute bad guesses by counting words in the list that aren't in the word, and good guesses are the other ones. The minimally required state makes the necessary functions emerge pretty easily.

All times are in UTC.