Re: [Haskell-cafe] How to declare a Typeless Function

2009-07-03 Thread Magnus Therning
On Fri, Jul 3, 2009 at 4:43 AM, Alexander
Dunlapalexander.dun...@gmail.com wrote:
 swap :: Array (Int, Int) a - [Int] - Array (Int, Int) a

 The lowercase a means that that type variable is polymorphic, i.e.
 it can be any type.

Another option would be to simply not put in type of 'swap', load it
in ghci and see what the compiler says the type is :-)

/M

 On Thu, Jul 2, 2009 at 8:05 PM, Fernan Bolandofernanbola...@mailc.net wrote:
 Hi

 I have a function that swaps rows of an array of double

 swap :: Array (Int,Int) Double - [Int] - Array (Int,Int) Double

 I then create a function that swaps rows of arrays of Complex Double

 swap :: Array (Int, Int) (Complex Double) - [Int] - Array (Int, Int)
 (Complex Double)

 In reality the function swap does not care whether its working on a
 double or a complex number.
 how do I declare swap so that it will work whether it's a complex or a
 double array.

 I tried googling but I wasn't sure what to google.

 fernan
 --
 http://www.fernski.com
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to declare a Typeless Function

2009-07-03 Thread Joe Fredette
It's important to note that such a function is not Typeless but rather 
Polymorphic -- that is, it is a type which can be satisfied for many 
values of it's type variables.


For instance, the function `(+) :: Num a = a - a - a` is polymorphic, 
since it's one type variable can be satisfied by any instance of the 
`Num` class. It's not that
the `(+)` function is Typeless (implying that it has no type) 
precisely the opposite, it has _many_ types. Haskell is clever enough to 
figure out which one you mean as you use it (most of the time, anyway).


/Joe

Magnus Therning wrote:

On Fri, Jul 3, 2009 at 4:43 AM, Alexander
Dunlapalexander.dun...@gmail.com wrote:
  

swap :: Array (Int, Int) a - [Int] - Array (Int, Int) a

The lowercase a means that that type variable is polymorphic, i.e.
it can be any type.



Another option would be to simply not put in type of 'swap', load it
in ghci and see what the compiler says the type is :-)

/M

  

On Thu, Jul 2, 2009 at 8:05 PM, Fernan Bolandofernanbola...@mailc.net wrote:


Hi

I have a function that swaps rows of an array of double

swap :: Array (Int,Int) Double - [Int] - Array (Int,Int) Double

I then create a function that swaps rows of arrays of Complex Double

swap :: Array (Int, Int) (Complex Double) - [Int] - Array (Int, Int)
(Complex Double)

In reality the function swap does not care whether its working on a
double or a complex number.
how do I declare swap so that it will work whether it's a complex or a
double array.

I tried googling but I wasn't sure what to google.

fernan
--
http://www.fernski.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

  

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe






  
begin:vcard
fn:Joseph Fredette
n:Fredette;Joseph
adr:Apartment #3;;6 Dean Street;Worcester;Massachusetts;01609;United States of America
email;internet:jfred...@gmail.com
tel;home:1-508-966-9889
tel;cell:1-508-254-9901
x-mozilla-html:FALSE
url:lowlymath.net, humbuggery.net
version:2.1
end:vcard

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to declare a Typeless Function

2009-07-02 Thread Fernan Bolando
Hi

I have a function that swaps rows of an array of double

swap :: Array (Int,Int) Double - [Int] - Array (Int,Int) Double

I then create a function that swaps rows of arrays of Complex Double

swap :: Array (Int, Int) (Complex Double) - [Int] - Array (Int, Int)
(Complex Double)

In reality the function swap does not care whether its working on a
double or a complex number.
how do I declare swap so that it will work whether it's a complex or a
double array.

I tried googling but I wasn't sure what to google.

fernan
-- 
http://www.fernski.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to declare a Typeless Function

2009-07-02 Thread Alexander Dunlap
swap :: Array (Int, Int) a - [Int] - Array (Int, Int) a

The lowercase a means that that type variable is polymorphic, i.e.
it can be any type.

Alex

On Thu, Jul 2, 2009 at 8:05 PM, Fernan Bolandofernanbola...@mailc.net wrote:
 Hi

 I have a function that swaps rows of an array of double

 swap :: Array (Int,Int) Double - [Int] - Array (Int,Int) Double

 I then create a function that swaps rows of arrays of Complex Double

 swap :: Array (Int, Int) (Complex Double) - [Int] - Array (Int, Int)
 (Complex Double)

 In reality the function swap does not care whether its working on a
 double or a complex number.
 how do I declare swap so that it will work whether it's a complex or a
 double array.

 I tried googling but I wasn't sure what to google.

 fernan
 --
 http://www.fernski.com
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe