0

This is prob an easy question but I just could not find the answer for this:

How can I access the parameters of a custom type?

Lets say my code is like this: (anotherFunc is only there to help me access the parameter)

data Shape = (Shape Color [Dimension])

func :: [Shape] -> [Shape]
func (x:xs) = anotherFunc x : func xs

anotherFunc :: [Shape] -> [Shape]
anotherFunc (Shape Color (x:xs)) = <some simple operations>

is there something similar to this??

func ( (Shape Color (x:xs)):shapes )

many thx!!

1
  • 3
    Maybe this helps you. Commented Feb 5, 2020 at 15:47

1 Answer 1

1

There is something very similar to that.

func ((Shape _ (x:xs)):shapes) = ...

However, your func just reimplements map, so you can use that and continue to use anotherFunc (which can be defined locally if you'd prefer):

func = map anotherFunc
  where anotherFunc (Shape c ds) = ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.