Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
39
Task/Monads-Maybe-monad/FreeBASIC/monads-maybe-monad.basic
Normal file
39
Task/Monads-Maybe-monad/FreeBASIC/monads-maybe-monad.basic
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
Type mmaybe
|
||||
As Integer value
|
||||
End Type
|
||||
|
||||
Function Bindf(m As mmaybe, f As Function(As mmaybe) As mmaybe) As mmaybe
|
||||
Return f(m)
|
||||
End Function
|
||||
|
||||
Function Unit(i As Integer) As mmaybe
|
||||
Dim As mmaybe m
|
||||
m.value = i
|
||||
Return m
|
||||
End Function
|
||||
|
||||
Function Decrement(mm As mmaybe) As mmaybe
|
||||
Dim As mmaybe result
|
||||
result.value = Iif(mm.value = 0, 0, mm.value - 1)
|
||||
Return Unit(result.value)
|
||||
End Function
|
||||
|
||||
Function Triple(mm As mmaybe) As mmaybe
|
||||
Dim As mmaybe result
|
||||
result.value = Iif(mm.value = 0, 0, 3 * mm.value)
|
||||
Return Unit(result.value)
|
||||
End Function
|
||||
|
||||
Dim As Integer values(3) = {3, 4, 0, 5}
|
||||
Dim As Function(As mmaybe) As mmaybe Ptr decrementPtr = @Decrement
|
||||
Dim As Function(As mmaybe) As mmaybe Ptr triplePtr = @Triple
|
||||
|
||||
For i As Integer = Lbound(values) To Ubound(values)
|
||||
Dim As mmaybe m1 = Unit(values(i))
|
||||
Dim As mmaybe m2 = Bindf(Bindf(m1, decrementPtr), triplePtr)
|
||||
Dim As String s1 = Iif(m1.value = 0, "none", Str(m1.value))
|
||||
Dim As String s2 = Iif(m2.value = 0, "none", Str(m2.value))
|
||||
Print Using "\ \ -> \ \"; s1; s2
|
||||
Next i
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue