[Python-ideas] Optional static typing -- late to the party
Bob Ippolito
bob at redivi.com
Wed Aug 20 22:03:25 CEST 2014
On Wed, Aug 20, 2014 at 11:38 AM, David Mertz <mertz at gnosis.cx> wrote:
> On Wed, Aug 20, 2014 at 11:14 AM, Bob Ippolito <bob at redivi.com> wrote:
> > There's the misunderstanding: PyContracts style contracts are not "easy
> enough" in Haskell.
>
> Well, for example, I found something like this for Haskell:
>
> newtype Digit = Digit { digitVal :: Int }
> deriving (Eq, Ord, Show)
> mkDigit :: Int -> Maybe Digit
> mkDigit n
> | n >= 0 && n < 10 = Just (Digit n)
> | otherwise = Nothing
>
>
> OK, sure it's not just one line. But now we have a predicate-restricted
> data type right in the type system. If we introduce a static type system
> in Python, I'd like it to be able to do that. […]
>
This isn't in the type system. This is what is called a smart constructor
[1]. These predicates are strictly a runtime construct, not compile time.
Guard syntax (a sequence of pipes each followed by a predicate and then an
equal sign and some term) is just a convenient way to write if[/else
if…]/else.
There are ways to do this specific sort of dependent typing [2] in Haskell
using an unholy combination of GHC-specific extensions and the absolute
latest compiler. This is exciting research, but not so practical today.
[1] http://www.haskell.org/haskellwiki/Smart_constructors
[2] http://en.wikipedia.org/wiki/Dependent_type
-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140820/3928677e/attachment.html>
More information about the Python-ideas
mailing list