fsharp 函数没有 return 任何东西
fsharp function doesn't return anything
我有以下用于简单算术表达式的小型分词器。我是 fsharp 的新手,我不知道为什么这个函数在被调用时没有 return 任何东西。有人可以帮忙吗?
let tokenizer s =
let chars1 = scan s
let rec repeat list =
match list with
| []->[]
| char::chars ->
match char with
| ')' -> RP::repeat chars
| '(' -> LP::repeat chars
| '+' -> Plus::repeat chars
| '*' -> Times::repeat chars
| '^' -> Pow::repeat chars
| _ ->
let (x,y) = makeInt (toInt char) chars
Int x::repeat chars
repeat chars1
未提供 scan
、toInt
、makeInt
的实现和表达式的联合类型,但可以推断为:
let scan (s:string) = s.ToCharArray() |> Array.toList
let toInt c = int c - int '0'
let makeInt n chars = (n,chars)
type expr = RP | LP | Plus | Times | Pow | Int of int
let tokenizer s =
let chars1 = scan s
let rec repeat list =
match list with
| []->[]
| char::chars ->
match char with
| ')' -> RP::repeat chars
| '(' -> LP::repeat chars
| '+' -> Plus::repeat chars
| '*' -> Times::repeat chars
| '^' -> Pow::repeat chars
| _ ->
let (x,y) = makeInt (toInt char) chars
Int x::repeat chars
repeat chars1
在这种情况下:
tokenizer "1+1"
给出:
val it : expr list = [Int 1; Plus; Int 1]
问题可能出在您的扫描功能的实现上。
我有以下用于简单算术表达式的小型分词器。我是 fsharp 的新手,我不知道为什么这个函数在被调用时没有 return 任何东西。有人可以帮忙吗?
let tokenizer s =
let chars1 = scan s
let rec repeat list =
match list with
| []->[]
| char::chars ->
match char with
| ')' -> RP::repeat chars
| '(' -> LP::repeat chars
| '+' -> Plus::repeat chars
| '*' -> Times::repeat chars
| '^' -> Pow::repeat chars
| _ ->
let (x,y) = makeInt (toInt char) chars
Int x::repeat chars
repeat chars1
未提供 scan
、toInt
、makeInt
的实现和表达式的联合类型,但可以推断为:
let scan (s:string) = s.ToCharArray() |> Array.toList
let toInt c = int c - int '0'
let makeInt n chars = (n,chars)
type expr = RP | LP | Plus | Times | Pow | Int of int
let tokenizer s =
let chars1 = scan s
let rec repeat list =
match list with
| []->[]
| char::chars ->
match char with
| ')' -> RP::repeat chars
| '(' -> LP::repeat chars
| '+' -> Plus::repeat chars
| '*' -> Times::repeat chars
| '^' -> Pow::repeat chars
| _ ->
let (x,y) = makeInt (toInt char) chars
Int x::repeat chars
repeat chars1
在这种情况下:
tokenizer "1+1"
给出:
val it : expr list = [Int 1; Plus; Int 1]
问题可能出在您的扫描功能的实现上。