{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, FlexibleContexts, EmptyDataDecls, ScopedTypeVariables, TypeOperators, TypeSynonymInstances, TypeFamilies, NoMonomorphismRestriction #-} module Automata where ----- I can't understand why doesn't automata representation as typeclasses work? {- class Eq a => DFA a b where start :: a delta :: b -> a -> a finals :: [a] dfa :: [b] -> a dfa = foldl (flip delta) start -} -- dfaAccept :: [b] -> Bool -- dfaAccept xs = (dfa xs) `elem` finals -- dfa () -- = foldl (flip delta) (start :: State t) class IsDFA t where data State t data Trans t start :: State t delta :: Trans t -> State t -> State t finals :: [State t] dfa :: [Trans t] -> State t dfa = foldl (flip delta) start -- members instance IsDFA () where data State () = S Int data Trans () = B Bool start = S 1 delta (B b) (S s) = if b then S s else S (s+1) finals = [S 3, S 4] t = dfa []