0

I have a object form this typedef.

type ListDA = (State, [((State, Char), State)], [State])

For a Function, i need the second argument and i don't now how i get this.

Smeagol86
  • 15
  • 1
  • 10
  • a duplicate of http://stackoverflow.com/questions/13472606/how-can-i-call-a-function-that-is-integrated-in-a-type-in-haskell (from the same coursework apparently). – Will Ness Nov 21 '12 at 14:57

1 Answers1

5

You could write a helper function:

snd3 :: (a, b, c) -> b
snd3 (_, b, _) = b

Or you could do the pattern matching directly in your function parameters, e.g. by replacing

yourFunction object = ...

with

yourFunction object @ (_, secondArgument, _) = ...

You may be better off defining a separate type:

data ListDA = ListDA {firstField  :: State,
                      secondField :: [((State, Char), State)],
                      thirdField  :: [State]}

This method defines accessor functions for you.

dave4420
  • 46,404
  • 6
  • 118
  • 152