ZVON > References > Haskell reference
| Indexes | Syntax | Prelude | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | >> IO << | Directory | System | Time | Locale | CPUTime | Random

Module: IO
Function: hGetPosn
Type: Handle -> IO HandlePosn
Description: Computation hGetPosn hdl returns the current I/O position of hdl as a value of the abstract type HandlePosn. If a call to hGetPosn h returns a position p, then computation hSetPosn p sets the position of h to the position it held at the time of the call to hGetPosn. Error reporting: the hSetPosn computation may fail with: isPermissionError if a system resource limit would be exceeded.
Related: hSetPosn

Example 1
File: /tmp/foo.txt : 

Hello, world!
Good bye!
Program source: 

import IO

main = do hdl <- openFile "/tmp/foo.txt" ReadMode
	  a <- hGetChar hdl
	  pos <- hGetPosn hdl
	  b <- hGetLine hdl
	  print (a,b)
	  
	  c <- hGetChar hdl
	  d <- hGetLine hdl
	  print (c,d)

	  hSetPosn pos
	  e <- hGetChar hdl
	  f <- hGetLine hdl
	  print (e,f)

Output: ('H',"ello, world!")

Output: ('G',"ood bye!")

Output: ('e',"llo, world!")