00:00:00 --- log: started haskell/02.03.09 01:12:35 --- join: ChoJin (~ask@cha213245038031.chello.fr) joined #haskell 01:51:11 --- join: shapr (~user@p-c2fbabf7.easy.inet.fi) joined #haskell 03:19:18 --- join: Yurik (~yrashk@gw.telcos.net.ua) joined #haskell 03:25:00 hi Yurik 03:26:02 shapr: hi 03:26:19 --- quit: shapr ("xemacs yeehaaa!") 04:02:53 --- quit: xbill ("Leaving") 05:08:38 --- quit: clausen (Remote closed the connection) 11:36:28 * LoganH is trying to figure out how to define a Church integer in Haskell so that he can define a mapping from a Church integer to a von Neumann integer. 11:37:47 I suppose it's not possible. 11:38:25 you could just define it as a lambda term, surely? 11:38:54 No, it's not quite that simple. 11:39:51 You need a function that transforms [] to [[]], then transforms [[]] to [[], [[]]], then [[], [[]]] to [[], [[]], [[], [[]]]]. And so on. :P 11:41:01 \xs -> []:map (\ys->[ys]) xs 11:42:15 Doesn't work, I'm afraid. 11:42:27 oh, I misread what you said above 11:42:30 I get errors like: Occurs check: cannot construct the infinite type: a = [a] 11:42:44 errm, I don't when I type that function in 11:42:59 Something like [[], [[]]] probably isn't even valid. 11:43:04 yes, it is 11:43:08 So the problem is I'm trying to do an impossible transformation. :P 11:43:11 Hmm. 11:43:17 Ok, it's a list of type [a] 11:43:26 [[[a]]] 11:44:42 How can I define a Church integer generating function that takes functions of type a -> [a]? 11:44:56 I can't remember how Church integers are generated 11:45:48 but I doubt you can, since IIRC they apply the input function n times, and you can't give a type to a function of type a->[a] applied n times 11:46:28 A Church integer is a function that applies a given function to a given expression n times. 11:46:40 church n = c 11:46:40 where 11:46:40 c f x = if n == 0 then x else c' f (f x) 11:46:40 where 11:46:41 c' = church (n-1) 11:46:43 (from foldoc) 11:46:50 unchurch c = c (+1) 0 11:47:25 so a -> [a] is a silly type for the input functions 11:56:48 I'm curious as how to define church to support this transformation, or use what I have already to do it. 12:34:35 c f x | n == 0 = c' f (f x) where c' = church (n-1) 12:34:49 isn't beautiful with | ? 12:35:01 instead of 'if' 12:35:06 oups 12:35:12 c f x | n == 0 = x 12:35:12 :) 12:35:28 c f x | otherwise = c' f (f x) 13:14:29 --- join: clausen (~andrew@c17997.eburwd3.vic.optusnet.com.au) joined #haskell 13:18:56 * clausen isn't grokking functors 13:19:06 anyone giving free lessons? (or a URL?) 13:41:21 --- join: DLid (hidden-use@host80-1-72-245.no-dns-yet.ntli.net) joined #haskell 13:42:07 does anyone know how i could write a recursive function which takes an int value and turns it into a binary list? 13:42:25 im new to haskell and struggling a bit 13:42:33 what's a binary list? 13:42:44 well i mean into a binary value 13:42:46 in a list 13:42:52 ah 13:43:00 liek: 13:43:02 like: 13:43:04 so 13 would give a list [1,1,0,1] 13:43:10 so, it's a list of integers? 13:43:11 but also i want the list backwards 13:43:13 [Int] 13:43:14 ? 13:43:18 i think that would be easier 13:43:30 sounds easy: 13:43:34 well i have defined a type Bit = Int 13:43:39 toBinary :: Int -> [Int] 13:43:47 yeah done that bit 13:43:58 toBinary 0 = [0] 13:44:04 toBinary 1 = [1] 13:44:43 * clausen thinks 13:45:05 i thought you would have to do something like 13 mod 2 13:45:09 if the number was 13 13:45:11 hmmm, you need to keep track of which place you are up to 13:45:21 * clausen was trying to be too sneaky 13:45:26 I think you need accumulator recursion 13:45:39 how do i do this? 13:45:47 hang on a sec 13:47:19 how can we do a bit mask in haskell ? 13:47:31 & ? 13:47:41 think so 13:47:54 apparantly not 13:48:17 google it? 13:49:07 toBinary n = (n & 1) : toBinary (n >> 1) (if >> is bit shift and & is bit mask 13:49:17 toBinary 0 = [0] 13:49:31 and same thing for 1, I think 13:49:40 well, I am new in haskell, so ... 13:50:01 hmm, i was thinking much simpler 13:50:28 such as if ns `mod` 2 then some_function_with_1 else some_function_with_0 13:51:22 clausen: what do you suggest? 13:52:25 ChoJin: still working on it... 13:52:41 oops DLid 13:54:03 got it :) 13:54:11 toBinary :: Int -> [Int] 13:54:12 toBinary 0 = [0] 13:54:12 toBinary x = if x `mod` 2 == 0 then 13:54:12 0:(toBinary (x `div` 2)) 13:54:12 else 13:54:12 1:(toBinary (x `div` 2)) 13:54:36 thx, ill try that 13:54:56 it puts an extra 0 in front 13:55:04 which is a bit yuck 13:55:11 (like you said, it's reversed too) 13:56:18 just add toBinary 1 = [1] 13:56:19 :) 13:56:34 mm there is a problem 13:56:43 oups, no :) 13:58:13 * clausen ponders better ways of writing that 13:58:48 toBinary :: Int -> [Int] 13:58:48 toBinary 0 = [0] 13:58:48 toBinary x = (x `mod` 2):(toBinary (x `div` 2)) 14:12:36 toBinary x = x `mod` 2:toBinary $ x `div` 2 14:12:51 maybe with some () :) 14:14:20 hehe 14:37:09 --- join: dave1 (hidden-use@host80-1-72-245.no-dns-yet.ntli.net) joined #haskell 14:37:10 --- quit: DLid (Read error: 104 (Connection reset by peer)) 14:37:20 --- nick: dave1 -> DLid 14:38:08 ok, i have another problem... 14:38:16 im making a make8 function... 14:38:26 which make8 :: [Bit] -> [Bit] 14:38:33 where type Bit = Int 14:39:15 and what i want is to get the length of the make8 and if the list is longer than 8, chop it down to just 8 14:39:19 so i have this code... 14:39:29 make8 ms = if length ms > 8 then 14:39:32 make8(init ms) 14:39:32 else 14:39:35 [0] 14:39:44 however, it keeps returning 0 14:39:51 could somebody help please 14:40:04 hmmm 14:40:27 what's init? 14:40:44 init removes the last element from a non-empty list 14:41:16 anyway, presumebly you want to add something to the list? 14:41:24 on the recursive call 14:41:43 * clausen playing table tennis 14:41:44 bbiab 14:42:13 well, if the length is less than 8 14:42:28 add 0's to the front of the list until it is of length 8 14:42:44 i mean, add 0's to the front sorry 14:43:29 is init not defined in the library? 14:45:00 anyone? 14:51:56 --- quit: DLid () 15:05:59 --- join: DLid (hidden-use@host80-1-72-245.no-dns-yet.ntli.net) joined #haskell 15:06:06 anyone here? 15:11:38 --- quit: DLid () 15:34:12 * clausen prods again: anyone know about functors? 15:58:47 * clausen found a really good introduction to category theory :) 15:58:59 http://wwwhome.cs.utwente.nl/~fokkinga/mmf92b.html 16:11:10 * Heffalump knows a bit about them 16:11:34 cool :) 16:11:43 well, I think this paper should explain everything 16:11:50 just, I'm trying to understand functors, as used in haskell 16:11:58 as in the type class? 16:12:01 or in general? 16:12:02 like, these pieces of code appear very Deep and Meaningful TM 16:12:05 Heffalump: the type class 16:12:47 instance Functor Maybe where 16:12:47 fmap f Nothing = Nothing 16:12:47 fmap f (Just x) = Just (f x) 16:12:49 ok, so the only point about the type class (and really functors in general) is that it's a means of "lifting" a function 16:12:54 instance Functor [] where 16:12:54 fmap = map 16:12:58 fmap :: (b -> c) -> a b -> a c 16:13:02 instance Functor ((->) a) where 16:13:02 fmap = (.) 16:13:15 so all that means is given a function from b to c, you can get one from Foo b to Foo c 16:13:22 for appropriate Foo 16:14:07 hmmm 16:14:19 what is Foo in this context? 16:14:24 say, [b] -> [c] ? 16:14:31 yep, that's a nice simple example 16:14:55 Foo could be a type constructor, or, more generally, anything that takes a type and gives you another type 16:15:08 so (->) a takes type b and gives you type a->b 16:15:23 so the fmap there does (b->c) -> ((a->b) -> (a->c)) 16:15:29 and it can be defined by 16:16:19 interesting 16:16:22 fmap (f :: (b->c)) (g :: (a->b)) (x :: a) = f (g x) 16:16:28 which simplifies to fmap = (.) 16:16:42 it all comes from the types 16:17:46 :: ? 16:17:57 * clausen never seen it used this way 16:20:46 I think that's valid syntax 16:20:52 I'm just saying that that parameter has that type 16:21:01 maybe I've been writing SML for too long :/ 16:21:20 hehe 16:21:38 I think you have to write it like this: 16:22:01 fmap :: (b->c) -> (a->b) -> (a -> c) (???) 16:22:19 fmap f g x = f (g x) 16:22:20 or something 16:25:03 probably 16:25:22 I wasn't really trying to write valid Haskell anyway, just illustrate what was going on 16:25:23 fmap f g = (.) 16:25:27 yep 16:25:31 oops 16:25:33 fmap = (.) 16:25:33 no, fmap = (.) 16:25:34 ;) 16:25:36 yeah :-) 16:25:48 the point is that once you've decided the type, there's actually only one definition that works 16:25:56 right 16:26:02 and you use fmap to get it 16:26:13 no, IM there's only one definition of fmap that works 16:26:17 ? 16:26:33 instance Functor ((->) a) where 16:26:40 given that you're trying to write that instance 16:26:43 fmap (+1) [1..5] 16:26:45 works 16:26:48 the only *possible* way to write fmap is fmap = (.) 16:26:57 ? 16:27:02 [or something equivalent] 16:27:11 isn't it different for each category? 16:27:19 (or set?) 16:27:25 yes, hence the "given that you're trying to write that instance" bit of what I said 16:27:27 (object?) 16:27:35 category 16:30:23 is there an identity category? 16:34:55 oops, an identity constructor 16:35:03 no, that makes no sense 16:36:47 Prelude> fmap (*2) (Just 5) 16:36:48 Just 10 16:37:06 * clausen beginning to grok this now :) 16:42:02 --- nick: Yurik -> Yurik[sleeping] 16:44:51 Heffalump: so, can you give me an example of fmap on functions? 16:44:56 (in the sense of (.)) 16:52:43 Prelude> (.) (*2) (+1) 5 16:52:44 12 16:52:51 Prelude> (fmap) (*2) (+1) 5 16:52:51 ERROR: Illegal Haskell 98 class constraint in inferred type 16:52:51 *** Expression : fmap (flip (*) 2) (flip (+) 1) 5 16:52:51 *** Type : (Num a, Functor ((->) a)) => a 16:53:11 instance Functor ((->) a) where 16:53:11 fmap = (.) 16:54:27 is Functor ((->) a) in the Prelude? 16:55:25 yes 16:55:48 (the last two lines, yes) 16:55:51 it's not in my Prelude.. 16:57:12 and yes, there is an identity constructor, data Foo a = Foo a 16:57:19 but you have to define the instance manually 16:58:39 thanks 16:58:44 strange there's no standard 16:58:51 --- quit: ChoJin ("bye !!!") 16:58:51 wait 16:58:54 it's not identity 16:59:02 because Foo a != Bar a 16:59:15 I think "id" is better 16:59:43 ok, there isn't a single definitive identity constructor 16:59:57 AFAIK you can't write instance Functor (\a -> a) 16:59:59 where a is a type 17:00:04 or anything like that 17:00:09 anyway 17:00:16 can you figure out why my fmap didn't work? 17:00:17 so you have to fake it with a dummy constructor 17:00:27 (fmap) (*2) (+1) 5 17:00:35 I get the same error but I expect it cos Functor ((->) a) isn't in my prelude 17:00:43 add it? 17:01:09 just did so 17:01:14 (not to my prelude, but another file) 17:01:17 Main> (fmap) (*2) (+1) 5 17:01:17 ;) 17:01:17 12 17:01:21 wow 17:01:30 so it looks like a hugs bug 17:01:34 and same with +98 17:01:40 Version: February 2001 17:01:42 is mine 17:01:56 * clausen has feb2000 17:02:07 dec 2001 is fine too 17:02:12 I don't think I have feb 2000 anywhere 17:02:21 it's what's in conectiva linux 17:02:30 and I haven't upgraded 17:02:49 oh, /me finds it 17:03:36 nope, works even with Feb 2000. 17:03:46 mercury[~]% cat foo.hs 17:03:46 instance Functor ((->) a) where 17:03:46 fmap = (.) 17:04:24 weird 17:04:34 what exactly are you doing? 17:04:35 I'll stick the instance definition in a test script... 17:04:43 Prelude> (fmap) (*2) (+1) 5 17:04:48 from vanilla prelude 17:04:56 (which DOES include that instance definition) 17:05:09 and you're sure it's loading the same prelude file you're checking for it? 17:05:19 no 17:05:25 good point ;) 17:06:32 ok, works in my test script now 17:06:37 anyway, it's strange it's not in the prelude 17:11:10 there's a lot of compromises in what did and didn't go into that, I think 17:11:38 you'd expect that you'd put in the functor defs for either everything or nothing... 17:16:37 hmm, but the others are more generally useful in some sense, I think that one is more of academic interest 17:17:09 none of them seem particularly useful 17:17:57 lists, maybe and IO are 17:18:02 cos they're Monads too 17:18:18 ah 17:18:28 and people write utility monad code that doesn't depend on a particular monad 17:18:39 I don't *think* ((->) a) is a monad 17:19:40 it'd need to have something of type (a->b) -> (b -> (a->c)) -> (a->c) 17:19:43 so actually I think it is 17:19:57 not sure what use it is though 17:24:17 (f >>= g) a = g (f a) a 17:30:11 doh, it's a Reader monad 21:36:21 --- nick: Yurik[sleeping] -> Yurik 22:32:03 --- quit: clausen ("send all money to /dev/clausen") 23:59:59 --- log: ended haskell/02.03.09