. , .
:
let mkList x = [x]
let mkTwo (f: 'a -> 'a list) = (f 42), (f "abc")
let two = mkTwo mkList
, . , , f: 'a -> 'a list, 'a mkTwo, f. , :
let mkTwo<'a> (f: 'a -> 'a list) = (f 42), (f "abc")
, mkTwo 'a. 'a mkTwo.
: , f 42, : ", f int , 'a int" - : ", , , int. , ".
f "abc". , 'a = int , , f : int -> int list, , string .
mapItems, : PausableStopWatchAction ( ), StopWatchAction ( ).
:
1:
let mkList x = [x]
let mkTwo f g = (f 42), (g "abc")
let two = mkTwo mkList mkList
mkList . , : int -> int list, string -> string list. , mkTwo .
2:
, , , . mapItems :
type MkList =
abstract member mkList : 'a -> 'a list
let mkList = { new MkList with member this.mkList x = [x] }
let mkTwo (f: MkList) = (f.mkList 42), (f.mkList "abc")
let two = mkTwo mkList
, , , , .
, "" action handlerfn
( , action handlerfn, , , ):
let mapItems
state
index
handlerfn =
state
|> Array.indexed
|> Array.map (
fun (i, item) ->
if index < 0 then
handlerfn item
else if i = index then
handlerfn item
else
item)
...
let handleAction
(mapItems : 'a [] -> int -> ('a -> 'a) -> 'a [])
state
action =
match action with
|Pausable action -> //actions specific to pausable stopwatch
let handler =
mapItems
state
action.index
match action.``type`` with
| Pause current ->
handler//call handler with state
(fun state ->
(handlePause current state))
| StopWatch action -> //actions from stop watch
let handler =
mapItems
state
action.index
match action.``type`` with
| Start current ->
handler//call handler with state
(fun state ->
//would use some of stopwatch handlers here
{state with
status ="started"
})