
I feel like there's a difference between partial functions in the
sense of length and partial functions in the sense of head.
If you have a partiality monad like the free monad over Identity:
data Partial a = Done a | NotYet (Partial a)
instance Monad Partial where
return = Done
Done a >>= f = f a
NotYet m >>= f = NotYet $ m >>= f
then length has a sensible and productive implementation in terms of it:
partialLength :: [a] -> Partial Int
partialLength = go 0 where
go n ls = seq n $ case ls of
[] -> Done n
_:ls' -> NotYet $ go (n + 1) ls'
This is similar to the mechanism that Agda and Idris use to denote a
potentially non-terminating result; with it, these languages are
Turing complete.
head and tail aren't like that, and should be marked differently in
the documentation.
On Fri, Aug 31, 2018 at 7:28 AM, Andrew Martin
I'm strongly +1 on this.
On Thu, Aug 30, 2018 at 8:10 PM Richard Eisenberg
wrote: Proposal: Mark partial functions in `base` as partial
Motivation: I'm about to teach Haskell to a classful of beginners. In my experience, they will soon reach for functions like `head` and `tail`, because pattern-matching is foreign to them. I would love just to be able to say "Don't use partial functions", but many students will not easily be able to tell partial functions from total ones.
I do expect this problem to work itself out rather quickly, and then students will be able to identify partial functions, but loudly marking partial functions as partial seems like a small service to everyone and a bigger one to newbies. I don't see any downsides.
Thoughts?
Thanks, Richard _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- -Andrew Thaddeus Martin
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries