user2070333
user2070333

Reputation: 335

Haskell basic [Either a b] input argument

How do i write the input argument for the following function guys??

A word is a list of such symbols, it has type [Either sigma var]. So, my second input will be a word and I don't know where to start about it. I think I can't write [Left sigma] or [Right var] since the whole either is type of a word.. Please help me out or please point me to somewhere i can read about it :)

genstep :: CFG sigma var -> [Either sigma var] -> [[Either sigma var]]

Thanks

Upvotes: 0

Views: 301

Answers (1)

Chris Taylor
Chris Taylor

Reputation: 47382

Here's something to start you off. Given a particular value of type CFG sigma var, the second argument can only be one of three things - either it's empty, or the first element is a Left, or the first element is a Right.

That means your function definition can start with

genstep :: CFG sigma var -> [Either sigma var] -> [[Either sigma var]]
genstep cfg []             = -- your definition here
genstep cfg (Left  s:rest) = -- your definition here
genstep cfg (Right v:rest) = -- your definition here

Is that enough to get you started?

Upvotes: 2

Related Questions