Static Typing in Python
Donn Cave
donn at u.washington.edu
Fri Mar 19 13:44:04 EST 2004
More information about the Python-list mailing list
Fri Mar 19 13:44:04 EST 2004
- Previous message (by thread): Static Typing in Python
- Next message (by thread): Static Typing in Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <tyf65d18c2c.fsf at pcepsft001.cern.ch>, Jacek Generowicz <jacek.generowicz at cern.ch> wrote: > Donn Cave <donn at u.washington.edu> writes: > > > Speaking of which, Haskell's type system supports type classes > > like Num (number), where Int and Float are instances of Num > > that implement its "+" function. > > This is pretty much what you'd do in OCaml too, I believe. > > > I'm probably leaving out a paragraph or two of the interesting > > parts, but the end result is that 1.5 + 1 works. Haskell is not > > weakly typed. > > But the point is that the programmer conrols whether the automatic > conversion is done or not. In weakly typed languages you get the > conversion whether you want it or not. I don't know, the mechanism I alluded to above doesn't really involve the programmer. module Main (main) where diff a b | a < b = b - a | otherwise = a - b main = do putStrLn (show (diff 2 5)) putStrLn (show (diff 2.3 5)) $ runhugs num.hs 3 2.7 Haskell automatically converts between numeric types, to perform arithmetic including comparisons. It doesn't just do it any time a value oppears in a context that requires a specific type - the awk/perl weak typing - but 1.5 + 1 does work, without any programmer intervention and without weak typing. Donn Cave, donn at u.washington.edu
- Previous message (by thread): Static Typing in Python
- Next message (by thread): Static Typing in Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list