0

I am new in haskell trying to do a small task

get1th ( a , _, _ , _) = a
foo input = 
    where input = (a:_,b:_,c:_,d:_)
    if ( length (get1th input) == 2 ) 
        then permutations[2]
        else permutations[3]

I am getting error saying

 parse error on input `where'

please give me a hint

1

2 Answers 2

3

where clause must be written at the end:

foo input = 
    if ( length (get1th input) == 2 ) 
        then permutations[2]
        else permutations[3]
    where (a:_,b:_,c:_,d:_) = input

UPDATED

It is also require to swap to (a:_,b:_,c:_,d:_) = input, reason - we want to extract values, but not to redefine input

Sign up to request clarification or add additional context in comments.

3 Comments

...but this is still really broken.
@user2277918 : correct last line to where (a:_,b:_,c:_,d:_) = input
The where clause seems totally unnecessary since none of the extracted values are used, and the failure to pattern match will result in an exception. At best, it restricts the inferred type of input to a 4-tuple of lists of something... Also, the permutations[2] looks like array indexing, but it is actually applying the permutations function to the list containing a single 2, which does not have a very interesting result.
1

As @wit has pointed out, where should be used in the end of expression. Why? Because:

  1. it is not a let;
  2. because it is related with all the previous context (block) of the function.

If you want to define an alias fronthand, you should use the let expression.

For more information about the differences and advantages of them, see the Let vs. Where.

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.