[Haskell-cafe] Matlab Style Logic Operations ala V1.*(V2>0) on Vectors and Matrices with HMatrix ??

Henning Thielemann lemming at henning-thielemann.de
Wed Dec 22 00:23:59 CET 2010

On Tue, 21 Dec 2010, gutti wrote:

> One thing that still confuses me a litte:
> polynom: double -> double ->double
> polynom x y = y^2 + x^2 + 2*x*y
> Type declaration for this polynom with two inputs

I guess you mean upper case "Double", otherwise it's a type variable and 
the compiler will ask for type constraint like "polynom :: Num double => 

Btw. the english word for the german "Polynom" is "polynomial". :-)

> - what is input and what is output and which way a I supposed to read it 
> ? -- x,y,polynom ? and when would I use double -> double => double

'polynom' is the function, 'x' and 'y' are its parameters (input), 
'polynom x y' is the function value (output). The type 'double -> double 
=> double' does not exist. The double arrow can be only at one place, 
immediately after the '::' and it separates the type constraints from the 
type expression.

polynomialFunction :: Num a => a -> a -> a

> Is there by the way the possibility in haskell to create functions with
> several outputs - ala Matlab function declation:
> function [N,k] = histogram(v,n)

You can use pairs for results (and of course for arguments, too). See for 

Prelude> :type divMod
divMod :: (Integral a) => a -> a -> (a, a)

What you cannot do in contrast to MatLab: You cannot omit function 
parameters in a function call, in a function implementation you cannot 
check for the number of parameters that the user has given actually 
(because the user cannot omit any argument at all), and you cannot check 
the number of requested output values.

For me these restrictions are an advantage. In MatLab, a function can 
perform something completely different depending on the number of output 
or input values.

> Hope I'm not asking too basic questions here, so feel free to point me to
> the right tutorial.

There's the haskell-beginners mailing list, but a good tutorial is 
certainly that by Hal Daume.

However I see, that the URL http://darcs.haskell.org/yaht/yaht.pdf does 
not work any longer, certainly due to the recent server movement. :-(

There is also various stuff at the Wiki:

More information about the Haskell-Cafe mailing list