0

I have written this property check in haskell:

prop_XY (x,y) sud = ((!!) (rows (sud)) x) !! y

and i need to define this locally, any suggestions on how to do it as i am clueless how to do it?

EDIT

So this is the two prop functions i have, and i need to define the second one locally.

-- Check update function
prop_update (x,y) sud n = prop_XY (x',y') (update sud (x',y') n) == n 
                          where x' = x `mod` 9 
                                y' = y `mod` 9

-- helper to find specific value 
prop_XY (x,y) sud = ((!!) (rows (sud)) x) !! y
Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45
  • What do you mean by "locally"? So the definition does not escape the scope of a function? Use `let` or `where` as in the current answer. So the definition does not escape the module? Use an explicit export list at the top `module Foo (... symbols not including prop_XY ...) where`. Something else? – Thomas M. DuBuisson Dec 19 '16 at 18:44
  • This is what our instructor said to us, "please define prop_XY locally instead since you only use it in prop_update." not really sure what he means by it @ThomasM.DuBuisson – Timo Cengiz Dec 19 '16 at 18:45
  • @TimoCengiz btw, `(!!)` is discouraged... not only will it potentially have to go through the entire list, but see also: https://wiki.haskell.org/Partial_functions – mb21 Dec 19 '16 at 18:55
  • @TimoCengiz The implication of that sentence is it should be local to the `prop_update` function. I would use either `let` or, probably better, `where` as shown by @CamilStaps. – Thomas M. DuBuisson Dec 19 '16 at 19:13
  • But i dont understand what "myGlobalFunction" is in my case? If you check the latest of my questions here in stack you can see the the whole code for this assignment. @ThomasM.DuBuisson – Timo Cengiz Dec 19 '16 at 19:17
  • @TimoCengiz Do you understand `where`? Do you now understand "local" to mean syntactically in scope only of `prop_update`? If so, you should be able to solve the problem. – Thomas M. DuBuisson Dec 19 '16 at 20:54

1 Answers1

3

If I understand you correctly, you can use a where clause:

prop_update ... = ... prop_XY (x,y) ...
  where
    prop_XY (x,y) sud = ((!!) (rows (sud)) x) !! y

See http://learnyouahaskell.com/syntax-in-functions#where for more information.

  • Totally missed this, but what is myGlobalFunction in my case thats what i dont get. I got the comment that i should do: " define prop_XY locally instead since you only use it in prop_update " – Timo Cengiz Jan 06 '17 at 18:23
  • I am a beginner at this so please have a look at the edit. Thank you – Timo Cengiz Jan 06 '17 at 18:31