hSeek in Windows

View: New views
3 Messages — Rating Filter:   Alert me  

hSeek in Windows

by Philippos Apolinarius :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

As many people guess, I am trying to port programs from Clean 1.3 to Haskell (and also to Clean 2.2, which is easier, but not much easier). Late Professor Wellesley wrote an interesting data base manager in Clean 1.3 that I would like to see in Haskell and Clean 2.2. However, when I tried to implement the BTree algorithm, GHC compiler did not accept hSeek and other IO operations.

D:\Programs\GHC-PROGS\docs\textut>ghc btree.hs --make
[1 of 1] Compiling Main             ( btree.hs, btree.o )
Linking btree.exe ...

D:\Programs\GHC-PROGS\docs\textut>btree.exe
btree.exe: teste.txt: hSeek: illegal operation (seek operations on text-mod
dles are not allowed on this platform)

To make a long story short, the program compiles, but does not run. This is interesting, because when Clean compiles an input/output operation it certainly executes it. In any case, what I should do in order to make file operations work on Windows? I need random access to text files.



All new Yahoo! Mail - Get a sneak peak at messages with a handy reading pane.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: hSeek in Windows

by Neil Mitchell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Philippos,

The secret is there in the error message: "seek operations on
text-moddles are not allowed on this platform"

You need to set your file in to binary mode, with hSetBinaryMode
(http://haskell.org/hoogle/?hoogle=hSetBinaryMode) or openBinaryFile
(http://haskell.org/hoogle/?hoogle=openBinaryFile). After doing that
hSeek will work.

Thanks, Neil

On Sun, Nov 1, 2009 at 8:44 PM, Philippos Apolinarius <phi500ac@...> wrote:

>
> As many people guess, I am trying to port programs from Clean 1.3 to Haskell (and also to Clean 2.2, which is easier, but not much easier). Late Professor Wellesley wrote an interesting data base manager in Clean 1.3 that I would like to see in Haskell and Clean 2.2. However, when I tried to implement the BTree algorithm, GHC compiler did not accept hSeek and other IO operations.
>
> D:\Programs\GHC-PROGS\docs\textut>ghc btree.hs --make
> [1 of 1] Compiling Main             ( btree.hs, btree.o )
> Linking btree.exe ...
>
> D:\Programs\GHC-PROGS\docs\textut>btree.exe
> btree.exe: teste.txt: hSeek: illegal operation (seek operations on text-mod
> dles are not allowed on this platform)
>
> To make a long story short, the program compiles, but does not run. This is interesting, because when Clean compiles an input/output operation it certainly executes it. In any case, what I should do in order to make file operations work on Windows? I need random access to text files.
>
>
> ________________________________
> All new Yahoo! Mail - Get a sneak peak at messages with a handy reading pane.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@...
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: hSeek in Windows

by Svein Ove Aas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Nov 1, 2009 at 9:44 PM, Philippos Apolinarius <phi500ac@...> wrote:
> To make a long story short, the program compiles, but does not run. This is interesting, because when Clean compiles an input/output operation it certainly executes it. In any case, what I should do in order to make file operations work on Windows? I need random access to text files.
>
The reason it fails to run is because, on windows, there isn't a
one-to-one mapping between characters and bytes on text files. You
have to use binary mode, in which case you're likely to see doubled
newlines - \r\n, or the other way around, I don't remember.

Which brings up the interesting question of how this works in 6.12,
which has text support for modes that are 1:N on /all/ platforms; e.g.
UTF-8. If hSeek works there, then chances are it'll work in text mode
on windows as well.

--
Svein Ove Aas
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe