00:00:00 --- log: started haskell/02.03.10 00:45:13 --- quit: Yurik (Remote closed the connection) 03:59:43 --- join: DLid (hidden-use@host80-1-72-245.no-dns-yet.ntli.net) joined #haskell 04:00:34 hi, is anybody here? 04:04:42 i could do with some help please 04:13:52 * Heffalump is sort of around 04:16:27 heffalump> could you help please? 04:17:57 just say your problem 04:18:02 ok... 04:18:21 im trying to make a chop8 :: [Bit] -> [Bit] 04:18:27 where type Bit = Int 04:19:38 what i want is to take a list and if it is longer than 8 chop it to 8, if it is equal to 8 leave it the same, and if its less than 8 to add 0's to the end of the list so that it euals 8 04:19:45 this is my code at the moment... 04:19:55 make8 :: [Bit] -> [Bit] 04:19:56 make8 ms = if length ms > 8 then 04:19:56 make8 (init ms) 04:19:56 else if length ms < 8 then 04:19:56 take (8 - length ms)(repeat 0) 04:19:56 else 04:19:58 ms 04:20:18 however, the length ms < 8 is wrong 04:20:20 yeah 04:20:27 you need to stick ms at the beginning 04:20:35 of the list 04:20:35 before take? 04:21:10 what do you mean? 04:21:22 ms:take (8 - length ms)(repeat 0) 04:21:24 ? 04:21:30 --- join: dave1 (hidden-use@host80-1-72-245.no-dns-yet.ntli.net) joined #haskell 04:21:36 --- quit: dave1 (Client Quit) 04:22:23 i dont know what to put 04:22:38 : takes an element and a list and sticks them together 04:22:41 what you need is ++ 04:22:48 which takes two lists and sticks them together 04:23:06 oh right, cheers 04:23:18 also, what would the base case be? 04:23:57 base case in what sense? 04:24:26 well, would there be a base case 04:24:40 i thought you had to have a base case with a recursive function? 04:25:20 The base case is the else part of the first if - the second if isn't necessary 04:25:59 also, is there a better way to ride this code using foldr? 04:26:56 Not using foldr, but you could write a much more concise version with take, repeat and ++ 04:27:16 what would that be? 04:27:50 take (8 - length ms)(repeat 0) == replicate (8 - length ms) 0 incidentally 04:28:13 take 8 (ms ++ repeat 0) 04:30:53 do i need the first line? 04:31:03 or just use take 8 (ms ++ repeat 0)? 04:31:04 no, that's the entire body then 04:31:08 yep 04:31:17 cause i tried take 8 (ms ++ repeat 0) and i get an error... 04:31:30 ah no i dont! 04:32:52 thx for your help, greatly appreciated 04:40:31 last question, im trying to define a function encode :: String -> [Bit] 04:40:53 it takes each letter of a string and turns it into an 8-bit number 04:41:00 i thought about using the ord function] 04:41:10 but how would i do this, im a bit confused by it all? 04:49:45 --- join: gene9 (dna@194.158.217.254) joined #haskell 04:50:29 use map 04:56:44 --- quit: gene9 (Read error: 104 (Connection reset by peer)) 04:59:38 --- join: gene9 (dna@194.158.216.91) joined #haskell 05:00:47 --- join: ChoJin (~ask@cha213245038031.chello.fr) joined #haskell 05:48:48 i have another problem... 05:48:53 this is my code... 05:48:53 encode :: String -> [Bit] 05:48:53 encode [] = [] 05:48:53 encode (e:es) = make8 (nat2bin (ord e)) ++ encode es 05:49:23 can anyone tell me whats wrong with this? 05:51:36 Heffalump, you suggested to use map beforehand 05:51:45 is that better than the code i have (which works)? 06:16:32 not hugely, no 06:17:15 Heffalump, im in a bit of bother with another function im trying to define and finding it difficult, see if you can advise me please... 06:17:57 you know yesterday i created nat2bin which took a number and turned it into a list of 0 and 1's (binary number) 06:18:02 well now i need to create bin2nat 06:18:22 which takes a binary list [1,0,1,1] and converts it into a number 06:18:31 how could i do this using foldr? 06:18:36 do you know? 06:19:41 you should be able to do it with either foldr or fold depending on which way round the list is 06:19:44 so [1,0,1,1] should give back the number 13 06:19:58 the list is back to front 06:20:00 it's generally easiest to write a recursive definition first, then work out how to change that into a fold 06:20:26 how would i write the recursive definition, i know i would need the zip function 06:20:31 but im having trouble working it out 06:23:22 you shouldn't need zip 06:23:40 what would bin2nat [] be? 06:25:51 --- quit: gene9 ("b") 06:33:35 --- join: gene9 (dna@194.158.216.91) joined #haskell 06:40:18 --- quit: gene9 ("b") 06:54:41 that would just return 0 06:54:50 this is what code i have so far... 06:55:03 bin2nat bs = zip bs [2^x | x <- [0..]] 06:55:19 so if i do bin2nat [1,0,1] at the prompt 06:55:22 it returns... 06:55:27 [(1,1),(0,2),(1,4)] 06:55:39 so how would i multiply each tuple together? 06:59:13 use map? 06:59:24 you don't really need to do that zip at all though 06:59:35 what would be a better way? 07:01:30 well, suppose you've already calculated what [1,0,1] is 07:01:57 then you can get the value for [1,1,0,1] by multiplying the value for [1,0,1] by 2 and adding the first 1 07:02:28 so how would i construct this into code? 07:02:43 so you are saying to use a recursive method 07:03:43 yes 07:03:56 how do i write this!? 07:04:35 you said you know what bin2nat [] is 07:04:55 now write bin2nat (b:bs) as something that uses b and bin2nat bs 07:05:08 bin2nat [] should be 1 07:05:47 0 surely? 07:05:53 you said that yourself 07:06:01 2^0 is 1 07:06:13 shouldnt it? 07:06:26 yes, but 0 * 2^0 is 0 07:06:37 hmm, suppose 07:07:14 [b0,b1,b2,...,bn] is b0 * 2^0 + b1 * 2^1 + ... + bn 2^n 07:07:33 --- join: ski (~md9slj@scooter.mdstud.chalmers.se) joined #haskell 07:07:33 and if there's nothing then it's just 0 07:07:37 ski! 07:07:41 im still unsure what the right code would be :( 07:07:48 hi Heffalump ! 07:08:22 dlid: suppose you know what bin2nat bs is - what is bin2nat (b:bs) ? 07:08:54 the b in bin2nat takes the first element of the list 07:09:02 and bs is the rest of the list 07:09:17 yep 07:09:37 so how do you calculate bin2nat (b:bs) given the value of bin2nat bs? 07:10:29 you would have to multiply b by 2^some_number then do this to the rest of the list recursively 07:11:10 no, because b is at the front of the list 07:11:22 and you said it's in reverse order of the binary digits 07:11:44 this is where im getting lost 07:11:58 i dont know how i could change this 07:12:22 DLid : do you want to just get a solution or do you want to understand how it works, and in that case : a direct recursive function or using higher-order foldr ? 07:12:50 both :) 07:13:06 I've run out of ways to explain it, perhaps ski could try 07:13:45 I think what you are missing is that b0 * 2^0 + b1 * 2^1 + ... + bn 2^n == b0 + 2(b1 + 2(b2 + ... + 2(bn-1 + 2 bn)) ... )) 07:13:48 so you have a list of bits ? 07:14:22 yep, a list of bits 07:14:33 and need to turn it into an int number 07:14:37 So given you have b0 and the rest of the list, what do you need to do? 07:14:45 and it's reverse order, i.e. [0,1,0,1] = 1010 = ten ? 07:14:51 yep 07:16:48 well if you have a list [b0,b1,b2 .. bn] = 2^n*bn + ... + 2^1 * b1 + 2^0 * b0 07:17:36 * ski i writting from within ssh from home so i have a little problem to write some chars (have to paste them), slow .. 07:18:21 so you want to multiple first bit with 1 , next with 2 , next with 4 , and so on ? 07:18:33 yep 07:19:01 so bin2nat (b:bs) using bin2nat [1,0,1,1] would give b the first 1 07:19:14 so if you write a plain recursive function you have to somehow compute the corresponding 1,2,4,8,.. for each bit .. 07:19:16 and this needs to be multiplied by 0 07:19:26 ski: huh? 07:19:36 no ! by 2^0 = 1 ! 07:19:50 Heffalump : what ? 07:20:13 1,0,1,1 = 13 07:20:13 >> [15:19] so if you write a plain recursive 07:20:13 >> function you have to somehow compute the 07:20:13 >> corresponding 1,2,4,8,.. for each bit .. 07:20:22 ohh. 07:20:32 no, s/ohh.// 07:20:38 i said that first of all, but then Heffalump you said there was an easier way 07:20:56 Heffalump : wasn't the list reversed from the "standard" bit order ? 07:21:10 ski: yes, so the least significant bit will be at the front of the list 07:21:16 [15:20] 1,0,1,1 = 13 07:21:27 backwards that is 07:21:39 1,0,1,1 = 1101 = 13 07:21:59 Heffalump : oh yes, of course. i was thinking of an accumulator containing 1,2,4,.. to multiply with .. 07:22:35 so using bin2nat [1,0,1,1] the b would return the very first value of 1 in the list 07:22:49 ski: yeah, that was DLid's original solution 07:23:02 no, actually, he used a zip 07:23:06 but it comes down to the same thing 07:23:38 so if you want to write this with an accumulator, then you make a help function and call that with the accumulator initialized to 1 and then double it on each recursive call. is this like what you wanted ? 07:24:02 i just wanted the easiest way 07:24:17 and then i was going to try and turn it into a high-order foldr funciton 07:25:25 so i need b * 2^0 which would be 1*2^0 then 0*2^1 then 1*2^2 etc 07:25:36 i understand how it works, but am unsure how to right this in haskell code 07:25:43 "easiest" is rather subjective 07:25:57 well : 2^0 * b0 + 2^1 * b1 + ... + 2^(n-1) * b(n-1) + 2^n * bn = b0 + 2 * (2^0 * b1 + 2^1 * b2 + ... + 2^(n-1) * n) ok so far ? 07:26:17 ok, yeah i got that 07:26:44 so b0 would be the b in (b:bs) 07:27:11 and that is = b0 + 2*(b1 + 2*(b2 + ... 2*(bn) ... )) (IIRC) 07:28:14 = b0 + 2*(b1 + 2*(b2 + ... 2*(bn + 0) ... )) 07:28:57 = b0 + 2*(b1 + 2*(b2 + ... 2*(bn b0 + 2*(b1 + 2*(b2 + ... 2*(bn + 2*0) ... )) 07:29:01 oops 07:29:14 b0 + 2*(b1 + 2*(b2 + ... 2*(bn + 2*0) ... )) i meant 07:30:22 so we start with 0 and multiple by two and add each bit, starting with the most significant bit (in this case the last) 07:32:22 so this explains foldr (\bi sum -> bi + 2*sum) 0 bits 07:32:58 it starts with 0 and then for each bit (from right to left) multiplies the sum by 2 and adds the bit 07:33:06 ok ? 07:33:54 bin2nat = foldr (\bi sum -> bi + 2*sum) 0 07:34:52 is this sufficient ? 07:39:51 anyone still here ? 07:40:05 * Igloo is 07:40:41 DLid perchance is testing out his program .. 07:40:41 * Heffalump too 07:40:51 but we knew that result anyway :-) 07:41:00 :-) 07:41:44 i wondered if the explanation was sufficient or if he wanted more elaboration or other .. 07:42:22 well, has there been many discussions here recently ? 07:43:10 * ski can't stay too long here. modem costs .. and others want to use the phone :( 07:43:51 I'd have thought broadband would be sanely priced in Sweden - most of teh rest of Europe seems to tend to be better than here - am I wrong? 07:44:24 And I haven't noticed too much recently - a bit on functors a while back but that's about all I remember 07:44:33 sorry, i was just discussing it with some friends 07:44:39 ill have a read of what you wrote! 07:45:19 Igloo : sadly i haven't broadband at home :-( (yet at least) 07:45:40 DLid : no problem :) 07:45:45 :-( 07:52:51 could you write the recursive function for me so i can then look at it and work it out please 07:53:04 ok : 07:53:08 if thats not too much hassle 07:53:14 thx 07:53:22 (you want the accumulator one ?) 07:53:38 yes please 07:54:05 bit2nat bs = helper bs 1 07:54:07 where 07:55:04 helper [ ] a = 0 07:55:30 helper (b:bs) a = a*b + helper bs (2*a) 07:55:37 or something like that 07:55:46 ok ill have a look, thx 07:55:58 i think one could also accumulate the sum if one wants 07:56:30 I'd say it came from 07:56:33 bit2nat [] = 0 07:56:43 bit2nat (b:bs) = b + 2 * bit2nat bs 07:57:29 yes, thats a accumulator-free version, good ! (it's equivalent to the foldr one i think) 07:59:37 Yeah - looking at the last line of that and of the definition of foldr should help see why the function folded is the correct one 08:00:02 yes, indeed. 08:09:16 well, i think i have to go now, bye 08:10:32 --- quit: ski ("someone want's to use the phone..") 08:22:55 --- quit: DLid () 08:45:24 Hmmm, can anyone think of a way of making this generic in any way? cons_5_2 y (x1, ys, x3, x4, x5) = (x1, y:ys, x3, x4, x5) 08:46:26 I don't think I can make cons_2 a class with the instance (,,,,) being that in Haskell as I don't think the type system can handle it 08:49:48 --- join: DLid (hidden-use@host80-1-72-245.no-dns-yet.ntli.net) joined #haskell 08:50:11 --- quit: clog (^C) 08:50:11 --- log: stopped haskell/02.03.10 08:50:48 --- log: started haskell/02.03.10 08:50:48 --- join: clog (nef@bespin.org) joined #haskell 08:50:48 --- topic: 'Have a library you'd like to donate, or one you'd like to see? Talk to us at http://sf.net/projects/haskell-libs/ | we be loggin' http://tunes.org/~nef/logs/haskell/ | welcome to the Haskell Dojo | julien is up to white belt! jewel and shapr are up to green belt!' 08:50:48 --- topic: set by shapr on [Wed Jan 30 14:36:17 2002] 08:50:48 --- names: list (clog DLid ChoJin LoganH Igloo smkl arete jemfinch Heffalump juhp Jiriki jlb) 08:50:57 im creating a chop8 :: [Bit] -> [[Bit]] 08:51:13 which takes each 8 bits and puts them into a list inside a list 08:58:34 how could i do this!? 09:06:52 i have... 09:06:52 chop8 :: [Bit] -> [[Bit]] 09:06:52 chop8 cs = [take 8(cs)] 09:07:01 but how would i get the next 8 values? 13:23:08 --- join: clausen (~andrew@c17997.eburwd3.vic.optusnet.com.au) joined #haskell 13:59:49 * Heffalump appears 14:00:41 Heffalump! 14:00:46 clausen! :-) 15:27:54 --- quit: clausen (Read error: 110 (Connection timed out)) 15:29:28 --- join: clausen (~andrew@c17997.eburwd3.vic.optusnet.com.au) joined #haskell 15:37:43 DLid: sorry, my ISP died for a bit 15:48:15 --- quit: DLid (Read error: 110 (Connection timed out)) 16:09:35 --- quit: clausen ("send all money to /dev/clausen") 16:11:03 --- quit: ChoJin ("bye !!!") 19:35:23 --- join: Bill` (~bill@ip68-7-7-120.sd.sd.cox.net) joined #haskell 19:35:59 is there a place where I can see some sample code? I'm talking like really easy stuff.... 19:36:30 hello Bill` 19:36:40 hi 19:36:42 :o) 19:36:48 anything in particular in mind? 19:37:04 maybe some math stuff 19:37:17 ? 19:37:52 have you looked around http://haskell.org? 19:38:28 there's links there to lots of stuff 19:38:35 hmmm, k... 19:38:48 reading the Haskell Report is a good starting place too 19:41:29 hmm.... what benefits does haskell have over a more mainstream language? 19:41:55 like java or c++? 19:42:08 or even perl/python? 19:42:55 over java and C++, it's more modern and powerful, since it's a functional programming language 19:43:53 over scripting language, well it's strongly typed for a start and there exist both an interpreter and compilers 19:44:40 also Haskell is beautiful IMHO, in the sense of Mathematical beauty 19:44:46 having interpreters and compilers is cool.... but I don't see what you mean by ""modern and powerful" ? 19:45:00 Haskell has a wonderful type s ystem. 19:45:12 And is the best language I've seen so far for generic programming. 19:50:59 yes, static type checking is powerful, and helps greatly to find most bugs at compile time not runtime 20:54:55 --- part: Bill` left #haskell 23:59:59 --- log: ended haskell/02.03.10