Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell vs python typing

I am looking for example where things in python would be easier to program just because it is dynamically typed?

I want to compare it with Haskell type system because its static typing doesn't get in the way like c# or java. Can I program in Haskell as I can in python without static typing being a hindrance?

PS: I am a python user and have played around little bit with ML and Haskell.. ... I hope it is clear now..

like image 662
StackUnderflow Avatar asked Jul 11 '26 21:07

StackUnderflow


2 Answers

Can I program in Haskell as I can in python without static typing being a hindrance

Yes.

To elaborate, I would say the main gotcha will be the use of existential types in Haskell for heterogeneous data structures (regular data structures holding lists of variously typed elements). This often catches OO people used to a top "Object" type. It often catches Lisp/Scheme programmers. But I'm not sure it will matter to a Pythonista.

Try to write some Haskell, and come back when you get a confusing type error.

You should think of static typing as a benefit -- it checks a lot of things for you, and the more you lean on it, the less things you have to test for. In addition, it enables the compiler to make your code much faster.

like image 92
Don Stewart Avatar answered Jul 14 '26 11:07

Don Stewart


Well for one you can't create a list containing multiple types of values without wrappers (like to get a list that may contain a string or an int, you'd have to create a list of Either Int String and wrap each item in a Left or a Right).

You also can't define a function that may return multiple types of values (like if someCondition then 1 else "this won't compile"), again, without using wrappers.

like image 23
sepp2k Avatar answered Jul 14 '26 11:07

sepp2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!