0

whats are the main differences between functions in Haskell , python and c?

I know that haskell function can get a function as a parameter? is it only in haskell?

Ohad
  • 1,563
  • 2
  • 20
  • 44
  • 2
    In Python you can also get a function as parameter. In fact, you can pass as argument anything you want, since [everything in Python is an *object*](http://stackoverflow.com/questions/865911/is-everything-an-object-in-python-like-ruby). – Christian Tapia Jun 24 '14 at 07:14
  • 2
    Getting a function as a parameter is easy even in C (via function pointers). The interesting part is creating new functions at run time. –  Jun 24 '14 at 07:17
  • In C you can also take a function as a parameter (by using a *function pointer*), though it's not nearly as pleasant as in Haskell or Python. – ruakh Jun 24 '14 at 07:17
  • Python and C don't have functions. – dfeuer Jun 24 '14 at 07:17
  • 2
    @dfeuer No need for nitpicking. They have things called functions. They don't enforce those things to be pure (but don't prevent it either), and they aren't identical to mathematical functions (but then again neither are Haskell's functions, they are just a bit closer). –  Jun 24 '14 at 07:18
  • 6
    That you wrote haskell with capital letter and python/c not? – 0xAX Jun 24 '14 at 07:20

1 Answers1

4

The fundamental difference between a Haskell function and a C function is in the fact that Haskell functions cannot have side effects. They cannot modify state when called and as such will return the same value when called repeatedly with the same parameters. This is not to say that you cannot have pure functions in C.

I would encourage you to read articles about functional programming and maybe a tutorial in Haskell to get a clearer idea about the subject.

Tarik
  • 10,810
  • 2
  • 26
  • 40
  • 1
    Unless, y'know, `unsafePerformIO`. –  Jun 24 '14 at 07:20
  • 1
    Re: "articles about functional programming": But of course, most functional programming languages are like C in this respect. Haskell is very unusual in *forbidding* side effects (without e.g. `System.IO.Unsafe`), so if this is "the fundamental difference", then most functional languages are fundamentally more similar to imperative languages than to Haskell. I never thought about it that way before . . . – ruakh Jun 24 '14 at 07:40