Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

>Aren't partial functions just curried? One or more arguments are bound, but not all?

No; a partial function is one that isn't well-defined for the whole of its domain. So, as per the article, head is a partial function because its type signature of [a] -> a implies that all arrays have a head value. But head [] does not. It's a partial function.



What approaches and tools do Haskell developers take to guard against this? I assume in the head case a Maybe would be a better return type? But then why doesn't the Haskell core do that in the head function?


In my experience (which is quite dated at this point; my Haskell usage is back to the turn of the millennium), the usual approach was pattern matching. i.e. if you knew you were going to use a function that might not be defined you would write an alternate case.

The type system isn't helping you at all there.

The feeling I had was that much of the prelude stuff was there to provide for beautiful, terse examples of functional programming and less to protect a software engineer.


Few interesting things in this comment, thanks! What you say makes sense; it sounds like Haskell can't literally hold my hand for me which is fair enough.

I've just started my Haskell journey and the undefined paths through partial function implementation caught me by surprise.

Just skimming Wikipedia it looks like I would want to use "total/strong functional programming" but apparently "total functional programming is not Turing-complete"

https://en.wikipedia.org/wiki/Total_functional_programming

Also found this on the Haskell site after some more googling:

https://wiki.haskell.org/Partial_functions


> Just skimming Wikipedia it looks like I would want to use "total/strong functional programming" but apparently "total functional programming is not Turing-complete"

It isn't, but usually Turing completeness isn't what you want. Take a look at Idris, where functions may explicitly be total or not-necessarily-total.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: