is haskell really purely functional? 27. Jun 2010

Wenn Haskell-Apologeten ihre Sprache als rein funktional anpreisen, dann meinen sie damit nicht etwa die Implementierung der Sprache sondern lediglich die Spezifikation des Sprachkerns. Theoretisch ist Haskell also rein funktional, aber in der Praxis gibt es dann so unsaubere Tricks wie unsafePerformIO welche es gestatten auf den Inhalt von IO-Monaden zuzugreifen und somit die Seiteneffektfreiheit der Sprache auszuhebeln. Es zwingt einen natürlich keiner dazu diese schmutzigen Hacks zu benutzen, aber allein die Tatsache, dass ein Programm in Haskell geschrieben ist, garantiert also keineswegs die Seiteneffektfreiheit.

 

Kommentare (2)

  1. Kevin Jardine About 8 hours later

    I saw your question on stackoverflow about this but just got an account there and can’t post comments there yet. So I thought that I’d answer directly here.

    Don Stewart has the correct answer and some of the other responses are incorrect or misleading.

    In particular, although Haskell encourages pure functional programming, it is not an exclusively pure functional programming language. It is a practical language and sometimes side effects are needed. These are usually isolated inside monads (eg. the IO or State monads) but as unsafePerformIO shows, side effects can even be hidden behind what appears to be pure functional code. This is discouraged, however.

  2. Stefan About 9 hours later

    Thank you for your comment. Yes, in the end I also found Don Stewarts Answer most convincing!

Kommentar schreiben

Markdown Syntax