필요한데가 많을 것 같아서 올려 놓는다.
// See http://msdn.microsoft.com/en-us/library/dd233248.aspx
let (|Integer|_|) (str: string) =
let mutable intvalue = 0
if System.Int32.TryParse(str, &intvalue) then Some(intvalue)
else None
let (|Float|_|) (str: string) =
let mutable floatvalue = 0.0
if System.Double.TryParse(str, &floatvalue) then Some(floatvalue)
else None
let parseNumeric str =
match str with
| Integer i -> printfn "%d : Integer" i
| Float f -> printfn "%f : Floating point" f
| _ -> printfn "%s : Not matched." str
parseNumeric "1.1"
parseNumeric "0"
parseNumeric "0.0"
parseNumeric "10"
parseNumeric "Something else"
실행 결과:
1.100000 : Floating point
0 : Integer
0.000000 : Floating point
10 : Integer
Something else : Not matched.
'프로그래밍 > F#' 카테고리의 다른 글
Hello 예제 for F# (0) | 2010.07.12 |
---|---|
if...else... 조건문 사용 예제 for F# (0) | 2010.07.12 |
F# 프로그래밍에서 한글 문제 (0) | 2010.07.12 |
F# 언어로 dnAnalytics를 이용한 행렬의 LU 분해와 SVD 분해 연습 (0) | 2010.07.08 |
F# 프로그래밍에서 String.split 가 없다고 불평할 때 (0) | 2010.07.08 |