How haskell types are different than regular PHP classes.
If i disable extending can I simulate something similar in PHP or JavaScript.
Haskell:
data Person = Person { firstName :: String
, lastName :: String
, age :: Int
, height :: Float
, phoneNumber :: String
, flavor :: String
age :: Person -> Int
age (Person p) = p.age
newAge = age(Person {age:=35})
Js:
class Person {
constructor(data) {
this.data = data
}
}
function age(p) {
if (p instanceof Person) return p.age
}
let personAge = age(new Person({age: 35})); // 35
There can be syntax errors but ignore them.
In a nutshell if I dont use inheritance the js code is similar to Haskell's.
I dont have pattern matching but i can use "if instanceof " to check types.