-
Notifications
You must be signed in to change notification settings - Fork 842
Closed
Description
I've learned a "skill" due to this question.
codewars: A Simple Postfix Language
And my answer is:
let begin_ f = f []
let push s n f = f (n :: s)
let add (a :: b :: s) cont = cont ((a + b) :: s)
let end_ = List.headthen we can call begin_ push 1 push 2 add end_ in F#!
In Haskell version, they advise:
The inferred type of a basic implementation is exponential in size to the expression. This causes type inference to take too long.
Hint: Use a typeclass
Hint: http://chrisdone.com/posts/haskell-constraint-trickfor this kind of code, the F# version will be slow too.
bad = begin push 1 push 1 push 1 push 1 push 1 push 1 push 1 push 1 push 1
add add add add add add add add endmy quetsion is why do our program will run slowly?
and if you just use the pipeline |> such as
let begin_ = []
let push s n = s::n
let add (a::b::s) = (a+b)::s
let end_ = List.headit will have a very beautiful performance.
Metadata
Metadata
Assignees
Labels
No labels