ListZipper.findLeft

39 views
Skip to first unread message

Christopher Mazey

unread,
Mar 3, 2015, 11:05:23 PM3/3/15
to haskell-...@googlegroups.com
findLeft and findRight fail

-- prop> findLeft (const True) -<< fromList xs == fromList xs

when

xs = 0 :. Nil


Apparently the tests and examples contradict each other; in this case the property seems include the focus of the ListZipper in its search, while the example

-- >>> findLeft (== 1) (zipper [2, 1] 1 [4, 5])
-- [] >1< [2,1,4,5]

does not.

The code:
-- | Seek to the left for a location matching a predicate, starting from the
-- current one.
--
-- -- /Tip:/ Use `break`
--
-- prop> findLeft (const True) -<< fromList xs == fromList xs
--
-- prop> findLeft (const False) (zipper l x r) == IsNotZ
--
-- >>> findLeft (== 1) (zipper [2, 1] 3 [4, 5])
-- [] >1< [2,3,4,5]
--
-- >>> findLeft (== 1) (zipper [2, 1] 1 [4, 5])
-- [] >1< [2,1,4,5]
findLeft
:: (a -> Bool) -> ListZipper a -> MaybeListZipper a
findLeft p
(ListZipper l x r) =
 
case break p l of
   
(_,Nil) -> IsNotZ
   
(l',h :. t) ->
      IsZ $
      ListZipper t
                 h
                 (reverse l'
++ x :. r)


Tony Morris

unread,
Mar 3, 2015, 11:36:03 PM3/3/15
to Christopher Mazey, haskell-exercises
Thanks Christopher, I have opened an issue:

https://github.com/NICTA/course/issues/126

I will fix it now.

--
You received this message because you are subscribed to the Google Groups "haskell-exercises" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-exerci...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Mazey

unread,
Mar 3, 2015, 11:46:51 PM3/3/15
to haskell-...@googlegroups.com, cjm...@gmail.com
Thanks, Tony.  And thank you very much for the course.  It is very good--I am learning and enjoying it a lot.
Reply all
Reply to author
Forward
0 new messages