Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Stack/F-Sharp/stack.fs
Normal file
20
Task/Stack/F-Sharp/stack.fs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
type Stack<'a> //'//(workaround for syntax highlighting problem)
|
||||
(?items) =
|
||||
let items = defaultArg items []
|
||||
|
||||
member x.Push(A) = Stack(A::items)
|
||||
|
||||
member x.Pop() =
|
||||
match items with
|
||||
| x::xr -> (x, Stack(xr))
|
||||
| [] -> failwith "Stack is empty."
|
||||
|
||||
member x.IsEmpty() = items = []
|
||||
|
||||
// example usage
|
||||
let anEmptyStack = Stack<int>()
|
||||
let stack2 = anEmptyStack.Push(42)
|
||||
printfn "%A" (stack2.IsEmpty())
|
||||
let (x, stack3) = stack2.Pop()
|
||||
printfn "%d" x
|
||||
printfn "%A" (stack3.IsEmpty())
|
||||
Loading…
Add table
Add a link
Reference in a new issue