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

2007-12-11 Thread apfelmus
jerzy karczmarczuk wrote: apfelmus: As Feynman put it: "What do you care what other people think?" It was not Feynman, but his wife. Thanks, I should have questioned my claim :) Regards, apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskel

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

2007-12-11 Thread jerzy . karczmarczuk
apfelmus: As Feynman put it: "What do you care what other people think?" It was not Feynman, but his wife. Jerzy Karczmarczuk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

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

2007-12-11 Thread apfelmus
Dan Weston wrote: Questioning apfelmus definitely gives me pause, but... Don't hesitate! :) Personally, I question everyone and everything, including myself. This is a marvelous protection against unintentionally believing things just because I've heard them several times like "Monads are ha

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

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 fu

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

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

2007-12-08 Thread apfelmus
Luke Palmer wrote: Hmm, this still seems ill-defined to me. compose :: (Int -> Int -> Int) -> (Int -> Int) -> Int -> Int -> Int Is a valid expression given that definition (with a,b = Int and c = Int -> Int), but now the arity is 4. That's correct, the arity of a function is not well-defined

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 c

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

2007-12-07 Thread Dan Weston
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 know a priori what the arity of the 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 > >

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 > fu

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 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)

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 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, wher

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 wri

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 instan

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

2007-12-07 Thread oleg
Philipp N. wrote: > i'm trying to wrap functions (a -> b -> ... -> z) of any arity to functions > of type ([String] -> y), where list of strings replaces the typed arguments. > the problem is, that you cannot distinguish type (x->y) from z, so these > instances are overlapping. to which apfelmus

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

2007-12-07 Thread apfelmus
Philipp N. wrote: i'm trying to wrap functions (a -> b -> ... -> z) of any arity to functions of type ([String] -> y), where list of strings replaces the typed arguments. one attempt looks like this (here written with type families, you can replace it by functional dependencies or what ever):