You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To create new data structure in JavaScript we also need to create a constructor function(class syntax sugar). But this way has a couple of problems like a lot of side effects, creating mutable instance and etc. With folktale library i want to use also derivation pattern for my custom data structure to make more consistent and eloquent code.
I propose Record as solve of class problem.
Haskell example:
data Person = Person { firstName :: String
, lastName :: String
, age :: Int
} deriving (Show)
tarantino = Person { firstName = "Quentin"
, lastName = "Tarantino"
, age = 55
}
putStrLn . show $ tarantino
-- ==> Person {firstName = "Quentin", lastName = "Tarantino", age = 55}
Folktale provide developer to use type coproduct, but developer has not ability to use type product.
We also have union type inside folktale. Developer will have consistence inside project and will lose a way to write mutable data structure with record . In additional, developer will get a stricter and declarative way for type definition.
Description
To create new data structure in JavaScript we also need to create a constructor function(class syntax sugar). But this way has a couple of problems like a lot of side effects, creating mutable instance and etc. With folktale library i want to use also derivation pattern for my custom data structure to make more consistent and eloquent code.
I propose Record as solve of class problem.
Haskell example:
Folktale example:
Why?
Folktale provide developer to use type coproduct, but developer has not ability to use type product.
We also have
union
type inside folktale. Developer will have consistence inside project and will lose a way to write mutable data structure withrecord
. In additional, developer will get a stricter and declarative way for type definition.Additional resources
https://blog.kentcdodds.com/classes-complexity-and-functional-programming-a8dd86903747
https://v1.realworldocaml.org/v1/en/html/records.html - OCaml Records
The text was updated successfully, but these errors were encountered: