Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-15 Thread Jacek Generowicz
Using Brandon's code as a starting point (as it's far neater than mine), let's try asking some questions about fractions (I've included the whole program at the end). questions = [ addition 1 2, addition (1%2) (1%3) ] This works, but the the fractions are shown as 1 % 2 and to make it

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-15 Thread Jacek Generowicz
On 2010 Oct 15, at 13:32, Jacek Generowicz wrote: questions = [ addition 1 2, addition (1%2) (1%3) ] My problem is that I don't see where I could add a type signature, but still keep addition :: a - a - Question polymorphic. Well, OK, I could write addition 1 (2 :: Int)

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Evan Laforge
How are you expecting to call the functions in that container?  for f in c: try: return f(*misc_args) except: pass? to_do = [(call, (AuntMabel,)),         (buy,  ([(12*kg, sugar), (6*bushel, wheat)])),         (introduce, (Romeo, Juliet))] for do,it in to_do:    do(*it) As has been

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
On 2010 Oct 14, at 05:27, Brandon Moore wrote: If you just want instances of questions you can keep it simple. How about something isomorphic to data Instance = Instance { question : String, answer : String, check : String - Bool } At first blush, I hated all those Strings hiding the

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
On 2010 Oct 14, at 05:39, Brandon Moore wrote: On Oct 13, 2010, at 7:44 PM, Jacek Generowicz jacek.generow...@cern.ch wrote: On 2010 Oct 14, at 01:32, Evan Laforge wrote: I think I'm starting too see what my problem is. I think it boils down to hankering for Duck Typing and variadic

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Joachim Breitner
Hi, Am Donnerstag, den 14.10.2010, 09:34 +0200 schrieb Jacek Generowicz: Another example: Let's say I need an Int - String. Both (fnA2 :: Banana - String) . (fnA1:: Int - Banana) and (fnB2 :: Onion - String) . (fnB1 :: Int - Onion) will do. So please allow me to store

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Max Bolingbroke
On 14 October 2010 08:34, Jacek Generowicz jacek.generow...@cern.ch wrote: Those other data might be the functions' arguments, or they might be other functions with which they are to be combined, or both. You can represent these as existential packages. However, as Oleg shows you can always use

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Ketil Malde
Jacek Generowicz jacek.generow...@cern.ch writes: Let's say I need an Int - String. Both (fnA2 :: Banana - String) . (fnA1:: Int - Banana) and (fnB2 :: Onion - String) . (fnB1 :: Int - Onion) will do. So please allow me to store (fnA1, fnA2) and (fnB1, fnB2) in the same place.

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Max Bolingbroke
On 14 October 2010 08:56, Max Bolingbroke batterseapo...@hotmail.com wrote: But if the only operation you ever do on this pair is (.), you may as well skolemise and just store (fnA1 . fnA2) directly. What is the advantage of doing otherwise? I forgot to mention that if you *really really* want

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
On 2010 Oct 14, at 09:19, Evan Laforge wrote: How are you expecting to call the functions in that container? for f in c: try: return f(*misc_args) except: pass? to_do = [(call, (AuntMabel,)), (buy, ([(12*kg, sugar), (6*bushel, wheat)])), (introduce, (Romeo, Juliet))]

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
On 2010 Oct 14, at 09:54, Joachim Breitner wrote: Hi, Am Donnerstag, den 14.10.2010, 09:34 +0200 schrieb Jacek Generowicz: Another example: Let's say I need an Int - String. Both (fnA2 :: Banana - String) . (fnA1:: Int - Banana) and (fnB2 :: Onion - String) . (fnB1 :: Int -

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
On 2010 Oct 14, at 09:56, Max Bolingbroke wrote: On 14 October 2010 08:34, Jacek Generowicz jacek.generow...@cern.ch wrote: Those other data might be the functions' arguments, or they might be other functions with which they are to be combined, or both. You can represent these as

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
On 2010 Oct 14, at 09:58, Ketil Malde wrote: Jacek Generowicz jacek.generow...@cern.ch writes: Let's say I need an Int - String. Both (fnA2 :: Banana - String) . (fnA1:: Int - Banana) and (fnB2 :: Onion - String) . (fnB1 :: Int - Onion) will do. So please allow me to store (fnA1,

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Ketil Malde
Jacek Generowicz jacek.generow...@cern.ch writes: def memoize(fn): cache = {} def memoized_fn(*args): if args not in cache: cache[args] = fn(*args) return cache[args] return memoized_fn Here's a simplified memoizer for Haskell: memoize :: (Integral t)

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
On 2010 Oct 14, at 15:24, Ketil Malde wrote: Jacek Generowicz jacek.generow...@cern.ch writes: def memoize(fn): cache = {} def memoized_fn(*args): if args not in cache: cache[args] = fn(*args) return cache[args] return memoized_fn Here's a simplified memoizer

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Jacek Generowicz
Thank you all for your contributions so far. Plenty of food for thought. I though I'd try to put it into practice and have a go at the motivating example I gave: essentially a EDSL for defining simple maths tests. I've included the beginnings of an attempt at the end. It started

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-14 Thread Brandon Moore
Thank you all for your contributions so far. Plenty of food for thought. I though I'd try to put it into practice and have a go at the motivating example I gave: essentially a EDSL for defining simple maths tests. If you have a Python version that has other features you would like, you

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-13 Thread Jacek Generowicz
On 2010 Oct 13, at 23:52, Evan Laforge wrote: I admit I haven't read this whole thread in detail, but when I want something with an implementation that can vary dynamically I just pass a different function. Of course. Your original python example is equivalent to just passing strings in

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-13 Thread Evan Laforge
I think I'm starting too see what my problem is. I think it boils down to hankering for Duck Typing and variadic functions. I fully appreciate that passing functions is a wonderful and powerful technique for catering for variation, but Haskell's type system cramps my style by insisting that I

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-13 Thread Jacek Generowicz
On 2010 Oct 14, at 01:32, Evan Laforge wrote: I think I'm starting too see what my problem is. I think it boils down to hankering for Duck Typing and variadic functions. I fully appreciate that passing functions is a wonderful and powerful technique for catering for variation, but

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-13 Thread Jacek Generowicz
BTW Thanks: This discussion has helped me gain a better understanding of some of the mechanisms at work, which I really appreciate. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-13 Thread Brandon Moore
If you just want instances of questions you can keep it simple. How about something isomorphic to data Instance = Instance { question : String, answer : String, check : String - Bool } You could make helper functions similar to your old code, like addition : (Int , Int) - Instance You might

Re: [Haskell-cafe] Client-extensible heterogeneous types (Duck-typed variadic functions?)

2010-10-13 Thread Brandon Moore
On Oct 13, 2010, at 7:44 PM, Jacek Generowicz jacek.generow...@cern.ch wrote: On 2010 Oct 14, at 01:32, Evan Laforge wrote: I think I'm starting too see what my problem is. I think it boils down to hankering for Duck Typing and variadic functions. I fully appreciate that passing functions is