turtle
turtle copied to clipboard
Implement something like `drop`
This is a reminder to myself to implement a function I mentioned on Stack Overflow:
http://stackoverflow.com/questions/28421469/how-to-drop-lines-when-streaming-from-a-file-using-haskell-and-the-turtle-librar/28422201#28422201
Here is the implementation:
import Data.IORef
import Turtle
drop :: Int -> Shell a -> Shell a
drop n s = Shell (\(FoldM step begin done) -> do
ref <- newIORef 0
let step' x a = do
n' <- readIORef ref
writeIORef ref (n' + 1)
if n' < n then return x else step x a
foldIO s (FoldM step' begin done) )
Note that I'd probably use a name other than drop to avoid a name clash with the Prelude
In that vein you might also want something like tail, no?
Elliot, yesterday I was actually thinking about using Turtle along with Frames in IHaskell to do stuff like head/tail files. Then I wondered what I'd name tail to prevent a name clash, since importing qualified didn't seem very appealing to me.
On Wed, Feb 11, 2015 at 12:11 PM, Elliot Cameron [email protected] wrote:
In that vein you might also want something like tail, no?
— Reply to this email directly or view it on GitHub https://github.com/Gabriel439/Haskell-Turtle-Library/issues/22#issuecomment-73932263 .
Yeah, tail conflicts with the Prelude, too.
Would it be possible (or even a good idea) to hide the Haskell prelude completely by default ?
@codygman Yes it's always nice not to need qualified imports. That being said, it's possible to simply import with an alias so that you can use it when ambiguities do arise. So you could still import Turtle as T (which still imports all of Turtle unqualified) and then only when there is an ambiguity use T.tail or something like that.
I'm reluctant to conflict with the prelude, mainly because I'd like this library to smoothly transition into learning Haskell in general.
In that case I'm confident you'll come up with good names. :) dropLines, tailLines come to mind...
The duplication of names is really what kills beginners. My feeling only from personal experience ;-)
How about skip?
Yeah, I like skip
The name skip is now taken. http://hackage.haskell.org/package/turtle-1.5.21/docs/Turtle-Pattern.html#v:skip
Perhaps shellDrop, dropShell or discard?