以下代码无法编译。我收到类型错误。我认为这将是更好的版本,因为它清楚地将两种不同的情况分开......该函数应该有助于确定有限状态机是否接受输入字。
import Text.Show.Functions
import qualified Data.Set as Set
import qualified Data.List as List
setTransition :: (Int -> Char -> [Int]) -> [Int] -> Char -> [Int]
setTransition delta [] sigma = []
setTransition delta xs@[x:xs'] sigma = foldl f [] xs
where f ys q = (delta q sigma) `List.union` ys
但是,这(删除了模式匹配)确实可以编译。有人能告诉我为什么吗??
import Text.Show.Functions
import qualified Data.Set as Set
import qualified Data.List as List
setTransition :: (Int -> Char -> [Int]) -> [Int] -> Char -> [Int]
setTransition delta [] sigma = []
setTransition delta xs sigma = foldl f [] xs
where f ys q = (delta q sigma) `List.union` ys
谢谢帮助