Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-10 Thread Dan Weston
Questioning apfelmus definitely gives me pause, but... id :: a - a-- arity 1 id = ($) :: (a - b) - (a - b) -- arity 2 I agree with the arities given above (but without quotes) and see no ill-definedness to arity. But these are two different classes of functions.

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-10 Thread Jonathan Cast
On 10 Dec 2007, at 11:33 AM, Dan Weston wrote: Questioning apfelmus definitely gives me pause, but... id :: a - a-- arity 1 id = ($) :: (a - b) - (a - b) -- arity 2 I agree with the arities given above (but without quotes) and see no ill-definedness to arity.

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-09 Thread Jonathan Cast
On 7 Dec 2007, at 12:39 PM, Dan Weston wrote: Luke Palmer wrote: On Dec 7, 2007 7:57 PM, Luke Palmer [EMAIL PROTECTED] wrote: On Dec 7, 2007 7:41 PM, Dan Weston [EMAIL PROTECTED] wrote: Luke Palmer wrote: You can project the compile time numbers into runtime ones: Yes, that works well if I

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Luke Palmer
On Dec 7, 2007 6:27 AM, Victor Nazarov [EMAIL PROTECTED] wrote: Cool solution and not so complicated and ad-hoc. But I'd like to ask isn't the following definition is more natural and simple? nary 0 x [] = x nary n f (x:xs) | n 0 = nary (n-1) (f $ read x) xs Sometimes it helps to write type

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Victor Nazarov
On Dec 7, 2007 4:46 PM, Luke Palmer [EMAIL PROTECTED] wrote: On Dec 7, 2007 6:27 AM, Victor Nazarov [EMAIL PROTECTED] wrote: nary 0 x [] = x nary n f (x:xs) | n 0 = nary (n-1) (f $ read x) xs Sometimes it helps to write type signatures for functions. As in this case, where you'll find

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Victor Nazarov
On Dec 7, 2007 2:52 PM, [EMAIL PROTECTED] wrote: In fact, that distinction is possible. The following article How to write an instance for not-a-function http://okmij.org/ftp/Haskell/typecast.html#is-function-type specifically describes a method of writing an instance which

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Luke Palmer
On Dec 7, 2007 6:21 PM, Dan Weston [EMAIL PROTECTED] wrote: This is great! Two questions: 1) I want to make sure the function arity matches the list length (as a runtime check). I think I can do this with an arity function using Data.Typeable. I came up with: arity f = a (typeOf f) where

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Dan Weston
This is great! Two questions: 1) I want to make sure the function arity matches the list length (as a runtime check). I think I can do this with an arity function using Data.Typeable. I came up with: arity f = a (typeOf f) where a tr | typeRepTyCon tr /= mkTyCon - = 0 | otherwise =

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Luke Palmer
On Dec 7, 2007 8:39 PM, Dan Weston [EMAIL PROTECTED] wrote: compose f g = f . g compose' f g x = f (g x) Are you saying that these two exactly equivalent functions should have different arity? If not, then is the arity 2 or 3? Prelude :t let compose f g = f . g in compose let

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Dan Weston
Luke Palmer wrote: You can project the compile time numbers into runtime ones: Yes, that works well if I know a priori what the arity of the function is. But I want to be able to have the compiler deduce the arity of the function (e.g. by applying undefined until it is no longer a function),

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Luke Palmer
On Dec 7, 2007 7:57 PM, Luke Palmer [EMAIL PROTECTED] wrote: On Dec 7, 2007 7:41 PM, Dan Weston [EMAIL PROTECTED] wrote: Luke Palmer wrote: You can project the compile time numbers into runtime ones: Yes, that works well if I know a priori what the arity of the function is. But I want

Re: [Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

2007-12-07 Thread Luke Palmer
On Dec 7, 2007 7:41 PM, Dan Weston [EMAIL PROTECTED] wrote: Luke Palmer wrote: You can project the compile time numbers into runtime ones: Yes, that works well if I know a priori what the arity of the function is. But I want to be able to have the compiler deduce the arity of the function