Re: RFC Proposal: Maybe monad and execution time polymorphic methods

From: Date: Tue, 29 Mar 2016 00:13:19 +0000
Subject: Re: RFC Proposal: Maybe monad and execution time polymorphic methods
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-91982@lists.php.net to get a copy of this message
Hi! > maybe PHP can. Maybe PHP will give me the polymorphism at execution time to > discern an empty Maybe from the one that is not. So I don't have to check In order for that to work, we should have a facility to: a) define union types b) ensure somehow that code dealing with the union type covers all variants c) if we really want to be able to handle such types smoothly, we need something like monads to be able to convert f(SomeClass $x) to f(Maybe $x). This does not sound trivial at all. (c) is not strictly required for the rest to work, but will also require some kind of generics, since Maybe should have information about contained type (maybe what? maybe file, maybe database connection, maybe pastrami sandwich?). If you give up on (c), you still need some facility like case-of for (b). And, of course, you will still need to write code to cover the "nothing" case of the Maybe. So it might be easier getting a code analyzer that would just identify missing null checks? -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#91982) next »