Hi everybody!
I just read in a book about functional programming (not about Haskell particularly) that the type of the concat function as follows
concat :: [[a]] -> [a]
then illustrated with this example:
concat ['a',' '] [] ['l','i','s'] ['t'] ??? (but didn't work in Haskell, perhapse it works in another functional language?)
of course concat [['a',' '],[],['l','i','s'] ['t']] = "a list" (but this worked in Haskell)
the whole problem is about how to define a function that takes an indetermined number of parameters with different types??? is it possible?? without using lists of course, because lists require the same type of elements,
[[a]] -> t
SORRY if I didn't explain as well.(a new Haskell programmer!)
1 reply to this topic
#1
Posted 03 February 2012 - 01:14 AM
|
|
|
#2
Posted 05 February 2012 - 10:12 AM
Haskell is strongly typed so it likes to know exactly what type of ever parameter in a function is. There are technically polyvariadic data types which allow for b trees and such in haskell but that's just a structured data type that can be extended.
A list of tuples being passed to a function could be considered polyvariadic as well but it's still structured data in the long run.
An argument list in C is in the long run just organized data albeit can be variable length.
There is some 'type magic' and monad use that can be done in haskell but it's beyond my level.
Here's some reading on the subject with code examples.
Varargs - HaskellWiki
Polyvariadic functions and keyword arguments
A list of tuples being passed to a function could be considered polyvariadic as well but it's still structured data in the long run.
An argument list in C is in the long run just organized data albeit can be variable length.
There is some 'type magic' and monad use that can be done in haskell but it's beyond my level.
Here's some reading on the subject with code examples.
Varargs - HaskellWiki
Polyvariadic functions and keyword arguments
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top










