Re: [Haskell-cafe] Intuitive function given type signature
On May 21, 2010, at 3:51 AM, Brent Yorgey wrote: On Thu, May 20, 2010 at 11:53:09AM +1200, Richard O'Keefe wrote: On May 20, 2010, at 3:18 AM, Brent Yorgey wrote: On Wed, May 19, 2010 at 04:27:14AM +, R J wrote: What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer The key point is the 'that would NATURALLY have', which I take to mean as a result of type inference without any forcibly imposed type signatures. Given that this is an exercise in Chapter 1, I kind of doubt this is really what it is supposed to mean. Are people reading chapter 1 really expected to understand the intricacies of type inference and the Num class? And to know about 'toInteger' and the fact that numeric constants are polymorphic? I really doubt it. I read the question much more simply, with naturally having a much more informal meaning than you suggest. I interpret the question as simply getting the reader some practice with basic higher-order types. The other possibility, of course, is a setup where Integer is the default type, so the function should just be f g = g 0 + 0. But naturally has to mean *something*, and the questions are clearly about type inference. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Intuitive function given type signature
On 20/05/2010, at 9:53 AM, Richard O'Keefe wrote: The key point is the 'that would NATURALLY have', which I take to mean as a result of type inference without any forcibly imposed type signatures. In my second edition of Bird, the question just says: Give examples of functions with the following types: Tom___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Intuitive function given type signature
On Thu, May 20, 2010 at 11:53:09AM +1200, Richard O'Keefe wrote: On May 20, 2010, at 3:18 AM, Brent Yorgey wrote: On Wed, May 19, 2010 at 04:27:14AM +, R J wrote: What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer The key point is the 'that would NATURALLY have', which I take to mean as a result of type inference without any forcibly imposed type signatures. Given that this is an exercise in Chapter 1, I kind of doubt this is really what it is supposed to mean. Are people reading chapter 1 really expected to understand the intricacies of type inference and the Num class? And to know about 'toInteger' and the fact that numeric constants are polymorphic? I really doubt it. I read the question much more simply, with naturally having a much more informal meaning than you suggest. I interpret the question as simply getting the reader some practice with basic higher-order types. I haven't read the Bird book though, so I could be wrong. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Intuitive function given type signature
On Wed, May 19, 2010 at 04:27:14AM +, R J wrote: What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer Well, this means f is given a function from Integer to Integer, and it has to somehow return an Integer, (possibly) using the function it is given. For example, f could just ignore its argument: f _ = 6 Or it could apply it to a particular input value: f g = g 0 I'll let you think of some other possibilities. g :: (Integer - Integer) - (Integer - Integer) g is given an Integer-Integer function and has to produce a different one. But as someone else pointed out, you can also think of this as g :: (Integer - Integer) - Integer - Integer That is, g is given an Integer-Integer function as well as an Integer, and must somehow use these things to produce another Integer. There are lots of ways to do this--I'll let you figure this one out. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Intuitive function given type signature
On May 20, 2010, at 3:18 AM, Brent Yorgey wrote: On Wed, May 19, 2010 at 04:27:14AM +, R J wrote: What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer Well, this means f is given a function from Integer to Integer, and it has to somehow return an Integer, (possibly) using the function it is given. For example, f could just ignore its argument: f _ = 6 That would NOT give f the right type. The type would be f :: Num r = a - r Or it could apply it to a particular input value: f g = g 0 That would NOT give f the right type. The type would be f :: Num a = (a - b) - b I'll let you think of some other possibilities. The key point is the 'that would NATURALLY have', which I take to mean as a result of type inference without any forcibly imposed type signatures. What kind of definition of f, *not* including :: anywhere, would result in Haskell inferring the desired signature? The key thing is that the types *must* be fully constrained to Integer. The simplest way to get something that is guaranteed to be the specific type Integer, as far as I can see, is to use something like toInteger 0. If we have identityForA :: A - A identityForB :: B - B then we can constrain a variable x to A using identityForA $ x and we can constrain a variable g to A-B using identityForB . g . identityForA. This is, in a sense, equivalent to providing a type signature, but it meets the formal requirements of these questions. identityForInteger = (+ toInteger 0) is an example. f g = g z + z where z = toInteger 0 does the trick here. m% ghci Prelude let f g = g z + z where z = toInteger 0 Prelude :type f f :: (Integer - Integer) - Integer ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Intuitive function given type signature
What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer g :: (Integer - Integer) - (Integer - Integer) (Bird problem 1.4.5) _ Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Intuitive function given type signature
This looks suspiciously like homework... 2010/5/19 R J rj248...@hotmail.com: What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer I can only think of one solution to this but it doesn't guarantee that it returns a value... g :: (Integer - Integer) - (Integer - Integer) Infinite possible functions. Don't forget, this is equivalent to: g :: (Integer - Integer) - Integer - Integer -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Intuitive function given type signature
On 19 May 2010, at 08:35, Ivan Miljenovic wrote: This looks suspiciously like homework... 2010/5/19 R J rj248...@hotmail.com: What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer I can only think of one solution to this but it doesn't guarantee that it returns a value... I can think of infinitely many solutions. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Intuitive function given type signature
2010/5/19 Miguel Mitrofanov miguelim...@yandex.ru: On 19 May 2010, at 08:35, Ivan Miljenovic wrote: 2010/5/19 R J rj248...@hotmail.com: What are some simple functions that would naturally have the following type signatures: f :: (Integer - Integer) - Integer I can only think of one solution to this but it doesn't guarantee that it returns a value... I can think of infinitely many solutions. Dammit, you're right; I was trying to be too clever :s -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe