Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-05 Thread Andrew Coppin
On 04/10/2011 07:08 AM, Dominique Devriese wrote: All, In case anyone is interested, I just want to point out an interesting article about the relation between Haskell type classes and C++ (overloading + concepts): http://sms.cs.chalmers.se/publications/papers/2008-WGP.pdf Dominique Thanks

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-05 Thread Alberto G. Corona
If a newbie considers this as something natural, this is another reason for syntactic sugaring of HList: http://www.haskell.org/pipermail/haskell-cafe/2011-April/090986.html 2011/10/2 Du Xi sdiy...@sjtu.edu.cn --I tried to write such polymorphic function: expand (x,y,z) = (x,y,z) expand

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-05 Thread Felipe Almeida Lessa
On Wed, Oct 5, 2011 at 8:45 AM, Alberto G. Corona agocor...@gmail.com wrote: If a newbie considers this as something natural, this is another reason for syntactic sugaring of HList: http://www.haskell.org/pipermail/haskell-cafe/2011-April/090986.html Exposing newbies to HList seems like a

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-04 Thread Dominique Devriese
All, In case anyone is interested, I just want to point out an interesting article about the relation between Haskell type classes and C++ (overloading + concepts): http://sms.cs.chalmers.se/publications/papers/2008-WGP.pdf Dominique 2011/10/3 Ketil Malde ke...@malde.org: sdiy...@sjtu.edu.cn

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-04 Thread oleg
sdiyazg at sjtu.edu.cn wrote: generalizedFilterMap (\[x,y,z]- if(x==1z==1)then [y*10] else [0]) (3,1) [1,2,3,4,1,2,1,3,1,4,1,5,2] [0,0,0,0,20,0,30,0,40,0,0] Of course, I could have simply used [Int] , (Num a)=[a] or (Int,Int,Int), but I'm trying to write code as generic as possible.

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-03 Thread sdiyazg
Quoting Richard O'Keefe o...@cs.otago.ac.nz: On 3/10/2011, at 7:15 AM, Du Xi wrote: I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-03 Thread Malcolm Wallace
Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? The simple C++ overloading you want to add to Haskell, is in fact rather semantically complex, and it

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-03 Thread sdiyazg
Quoting Felipe Almeida Lessa felipe.le...@gmail.com: On Sun, Oct 2, 2011 at 4:26 PM, Edward Z. Yang ezy...@mit.edu wrote: What are you actually trying to do? This seems like a rather unusual function. If you're new to the language, most likely you're doing something wrong if you need this

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-03 Thread sdiyazg
Quoting Andrew Coppin andrewcop...@btinternet.com: On 02/10/2011 07:15 PM, Du Xi wrote: In C++, the code is inferred from the types. (I.e., if a function is overloaded, the correct implementation is selected depending on the types of the arguments.) In Haskell, the types are inferred from the

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-03 Thread Ketil Malde
sdiy...@sjtu.edu.cn writes: This has nothing to do with OOP or being imperative. It's just about types. Of course, it's not necessarily linked to OOP, but OO languages - to the extent they have types - tend towards ad-hoc polymorphism instead of parametric polymorphism. There are different

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Yves Parès
2-tuple and 3-tuple *are not the same type*. So to do this you must use typeclasses. Plus you have to deal with the type parameters class To3Tuple a where expand :: a - (Int, Int, Int) instance To3Tuple (Int, Int, Int) where expand = id instance To3Tuple (Int, Int) where expand (x,y) =

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Andrew Coppin
On 02/10/2011 02:04 PM, Du Xi wrote: --It still didn't compile. I think the reason is that the following is disallowed: f::a-b f x = x The type a - b doesn't mean what you think it does. It does /not/ mean that f is allowed to return any type it wants to. It means that f must be prepaired

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread David Barbour
On Sun, Oct 2, 2011 at 6:04 AM, Du Xi sdiy...@sjtu.edu.cn wrote: --Is it possible to get around this and write the expand function? Of course, x and y may be of different types Not as written, but try HList. http://hackage.haskell.org/package/HList

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Du Xi
Quoting Andrew Coppin andrewcop...@btinternet.com: On 02/10/2011 02:04 PM, Du Xi wrote: --It still didn't compile. I think the reason is that the following is disallowed: f::a-b f x = x The type a - b doesn't mean what you think it does. It does /not/ mean that f is allowed to return any

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread David Barbour
On Sun, Oct 2, 2011 at 8:45 AM, Du Xi sdiy...@sjtu.edu.cn wrote: Then again , in typeclass definition how can I express the type a-b where a is the type parameter of the class and b is a type deduced from the rules defined in each instance of the class, which varies on a per-instance basis?

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Victor Gorokgov
02.10.2011 19:55, David Barbour пишет: Use TypeFamilies. {-# LANGUAGE TypeFamilies #} ... type family FType a :: * type instance FType Char = Float type instance FType Double = Int class ExampleClass a where f :: a - FType a Better to include type in class. class ExampleClass a where type

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Du Xi
Quoting Victor Gorokgov m...@rkit.pp.ru: 02.10.2011 19:55, David Barbour пишет: Use TypeFamilies. {-# LANGUAGE TypeFamilies #} ... type family FType a :: * type instance FType Char = Float type instance FType Double = Int class ExampleClass a where f :: a - FType a Better to include type

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread sdiyazg
Finally I got what I meant: class ExpandTuple t where type Result t expand :: t-Result t instance (Integral a)=ExpandTuple (a,a) where type Result (a,a) = (a,a,a) expand (x,y) = (x,y,1) instance (Integral a)=ExpandTuple (a,a,a) where type Result (a,a,a)

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Edward Z. Yang
What are you actually trying to do? This seems like a rather unusual function. Edward Excerpts from sdiyazg's message of Sun Oct 02 15:17:07 -0400 2011: Finally I got what I meant: class ExpandTuple t where type Result t expand :: t-Result t instance (Integral a)=ExpandTuple

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Felipe Almeida Lessa
On Sun, Oct 2, 2011 at 4:26 PM, Edward Z. Yang ezy...@mit.edu wrote: What are you actually trying to do?  This seems like a rather unusual function. If you're new to the language, most likely you're doing something wrong if you need this kind of function. =) -- Felipe.

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Brandon Allbery
On Sun, Oct 2, 2011 at 15:17, sdiy...@sjtu.edu.cn wrote: But it's so verbose (even more so than similar C++ template code I guess), introduces an additional name (the typeclass) into the current scope, and requires 2 extensions: TypeFamilies and FlexibleInstances.Is there a cleaner way to do

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Antoine Latter
On Sun, Oct 2, 2011 at 2:17 PM, sdiy...@sjtu.edu.cn wrote: Finally I got what I meant: class ExpandTuple t where        type Result t        expand :: t-Result t instance (Integral a)=ExpandTuple (a,a) where        type Result (a,a) = (a,a,a)        expand (x,y) = (x,y,1) instance

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Tom Murphy
Assuming that z :: Int, you can declare an algebraic datatype data TwoOrThree a b = Three (a, b, Int) | Two (a, b) deriving(Show, Eq) -- so you can experiment And then define expand as expand :: TwoOrThree a b - (a, b, Int) expand (Three tuple) = tuple expand (Two (a, b))

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Andrew Coppin
On 02/10/2011 07:15 PM, Du Xi wrote: I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? In C++, the code is

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Scott Turner
On 2011-10-02 14:15, Du Xi wrote: I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? Simple overloading is known as

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Yves Parès
Yes, do you have a Python background? Because I've often see misunderstanding about the utility of tuples with persons who were used to Python, because Python tutorials usually induce * BAD* practices in this respect (considering tuples and lists equivalent, for instance). Add to this the dynamic

Re: [Haskell-cafe] Is it possible to represent such polymorphism?

2011-10-02 Thread Richard O'Keefe
On 3/10/2011, at 7:15 AM, Du Xi wrote: I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? It's not SIMPLE