Haskell launch questions ... please explain this to me

I have to write some haskell program, but I don't know where to start. I will be very grateful if you can point out some resources to me to read or explain the question to me. I am sure that this is something completely amateurish, but I really need a starting point.

data DFA q o                =  DFA (q -> o -> q) q [q]
data NFA q o                =  NFA (q -> o -> [q]) [q] [q]
-- I really realy don't understand the declarations here
-- I can guess that q is somewhat related to Q and o to E, but don't get what it really means

data Q                      =  Q0 | Q1 | Q2
                               deriving (Eq, Enum, Bounded)

data E                      =  A | B


-- what does n1 do ??
n1                          :: NFA Q E
n1                          =  NFA d [Q0] [Q2] -- i see [Q0] refers to set of initial states and [Q2] refers to final states :)
                               where
                                   d Q0 A = [Q0]
                                   d Q0 B = [Q0, Q1]
                                   d Q1 _ = [Q2]
                                   d Q2 _ = []


-- the following functions are for me to write
starDFA :: Eq q => DFA q o -> [o] -> Bool
--for the above function, what are the arguments the function takes in ?
--how can we relate q with Q and [o] with [E] ??

Any explanations or links to the right starting points will be really helpful to me. Sorry to ask such a dumb question, but I really don't know where to start :)

thank

+5
source share
3 answers

Haskell Great Good!, , Haskell . , , .

, , - data, , ( 2 3), intro, .

q vs q o vs E.

, , , , Haskell, , 4 5 , .

, , , .

+17

haskell , , , newtype .

data​​strong > , , .

data E = A | B

E, .
sum. ? .

useE :: E -> String
useE A = "This is A"
useE B = "This is B"

, .

data Q =  Q0 | Q1 | Q2 deriving (Eq, Enum, Bounded)

, , sum, Q, : Q0, Q1 Q2. , , ( ), ( ) Eq, Enum, Bounded class. ? . , Q, ?

enumQ :: Q -> Int
enumQ x = fromEnum x

, , : info Enum ghci. , . ( |), , .

, .

data DFA q o =  DFA (q -> o -> q) q [q]
data NFA q o =  NFA (q -> o -> [q]) [q] [q]

- , .

data DFA q o = DFA (q -> o -> q) q [q]  

.

  • , . , .
  • , . , , () .

, , ,

  • [x]: , , , [Int] = > Int
  • x: , (Int, Char, String...)
  • x → y: , , x, y.
  • x → y → z: , , x a y, z. , (x- > y) z. , .

, , , , q o, . , .

, , , , n1?

.

+6

, Haskell, DFA NFA - (, NFA):

( :) NFA - , (q o) .

( :) NFA NFA :
(1) "(q → o → [q])", , , q o, q, ([q])
(2) "[q]", q
(3) "[q]", q

n1 NFA, ,

n1                          =  NFA d [Q0] [Q2]

So, we can conclude that:
(1) d is a function that takes two parameters: a 'q' and 'o' and returns a list q's
(2) [Q0] - a list q, and
(3) [Q2] - list q.

And, indeed, the definition of d follows:
d takes two parameters: "Q" and "E" and returns a list Q (which, as we know, can be either Q0, Q1, or Q2) or an empty list.

I hope this helps a little and / or maybe someone can clarify and correct my vague understanding.

+3
source

All Articles