[파일명: TestStringFindInList.fs]------------------------------------------------
#light
let find arr s = List.findIndex (fun x -> x = s) arr
let printList data =
let rec loop l =
match l with
| x::[] -> printf "%O" x
| x::xs -> printf "%O, " x; loop xs
| [] -> printf ""
printf "["
loop data
printf "]"
// Begin here
let cmdArgs = System.Environment.GetCommandLineArgs()
let words = ["하나"; "둘"; "셋"; "넷"; "다섯"; "여섯"]
printf "list: "
printList words
printfn ""
let where1 = find words "셋"
if where1 >= 0 then
printf "발견! "
printf "Next word of 셋 in list: %O" (words.[where1+1])
printfn ""
printfn "Sorting..."
let otherwords = words |> List.sort |> List.sort
printf "list: "
printList otherwords
printfn ""
let where2 = find otherwords "셋"
if where2 >= 0 then
printf "발견! "
printf "Next word of 셋 in list: %O" (otherwords.[where2+1])
printfn ""
------------------------------------------------
컴파일> fsc --codepage:949 TestStringFindInList.fs
실행> TestStringFindInList
list: [하나, 둘, 셋, 넷, 다섯, 여섯]
발견! Next word of 셋 in list: 넷
Sorting...
list: [넷, 다섯, 둘, 셋, 여섯, 하나]
발견! Next word of 셋 in list: 여섯
'프로그래밍 > F#' 카테고리의 다른 글
int 타입과 bigint 타입 간 상호 변환 with F# (0) | 2010.07.18 |
---|---|
Pollard's rho method 소개: 정수의 인수분해(factorizing integers) with F# (0) | 2010.07.17 |
스트링 배열 정렬(sorting)하기 with F# (0) | 2010.07.16 |
손으로 계산하는 긴자리 곱셈표 만들기 with F# (0) | 2010.07.15 |
문자열 거꾸로 하기 with F# (0) | 2010.07.15 |