Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

findM cannot keep original state #172

Open
elvis-sik opened this issue Jan 15, 2016 · 3 comments
Open

findM cannot keep original state #172

elvis-sik opened this issue Jan 15, 2016 · 3 comments

Comments

@elvis-sik
Copy link

While attempting to implement findM, I ran into problems with this test:

    >>> let p x = (\s -> (const $ pure (x == 'i')) =<< put (1+s)) =<< get in runState (findM p $ listh ['a'..'h']) 8
    (Empty,8)

I couldn't do it (could only get (Empty, 16) so I looked the answer here: https://github.com/tonymorris/course/blob/master/src/Course/State.hs

The answer as semantically the same as mine, though just as a sanity check I copied and pasted it, ran stack test and it still gave me an error.

@tonymorris
Copy link
Contributor

Is it possible that pure, put, (=<<) for State is incorrect.

@elvis-sik
Copy link
Author

Thanks for the suggestion, I checked those. No, that wasn't it. The problem is the function was being applied to 8 in here https://github.com/NICTA/course/blob/master/src/Course/State.hs instead of 0

@cmal
Copy link

cmal commented Dec 26, 2019

Probably the same problem, I got this when running test:

  test/Course/StateSpec.hs:59:
  1) Course.State.findM find 'c' in 'a'..'h'
       expected: (Full 'c',3)
        but got: (Full 'c',8)

I didn't find a right implementation of findM from google, my implementation use foldRight and it is definitely wrong. It cannot pass the test, and makes the isHappy implementation go into infinite loop.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants