the following code does not compile. I get a type error. I thought this would be the nicer version, as it clearly seperates the two different cases... The function is supposed to help decide whether a Finite State Machine accepts an input word.
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
This (removed the patternmatching) however does compile. Can somebody tell me why??
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
Thx for helping
xs@(x:xs')
, notxs@[x:xs']
. – luqui