[Haskell-cafe] HXT and xhtml page encoded in cp1251

2011-04-18 Thread Dmitry V'yal

Greetings,

I'm writing a small webcrawler. Usually I used tagsoup for such tasks 
but this time I decided to give hxt a try.


Unfortunately, I ran into the troubles with character encodings. The 
site I'm targeting uses cp1251, which is the one of the most popular 
among sites in Russian. Pages contain the following meta tag

meta http-equiv=content-type content=text/html; charset=windows-1251 /

The readDocument arrow fails with the following message:

fatal error: encoding scheme not supported: WINDOWS-1251

Can someone suggest a workaround for my use case?

Best regards,
Dmitry

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] handling multiple versions of a data structure

2010-12-19 Thread Dmitry V'yal

On 17.12.2010 01:09, Jeremy Shaw wrote:

Hello,

You should use happstack-data for this (you do not need the other
happstack components to use happstack-data)*. It was created to solve
this exact problem.

happstack-data builds on type of the 'binary' library and adds versioned
data types and automatic version migration.


Thanks! Looks like what I need. There is a one problem, though. I don't 
have a time machine. I mean right now I have A primitive format based on 
Show instance and I'd like to maintain the compatibility with it.


Is it possible to force a particular on-disk format for a particular 
version of data type? I guess I should write a Serialize instance 
myself. Are there any pitfalls awaiting me?


Best wishes,
Dmitry

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] handling multiple versions of a data structure

2010-12-16 Thread Dmitry V'yal

Greetings,

while developing my neural net simulator I stumbled upon a problem.

I have a data type NeuralNet and use Show and Read instances for saving 
and loading configurations. As time passed, I changed the data type, so 
the program can no longer load files saved in previous versions.


I want fix it. My current idea looks as follows. I'm going to create a 
bunch of types NN1, NN2, NN3..NNn for different versions and write 
converters c12 :: N1 - N2, c23 :: N2 - N3 and so on.


But how to organize the whole process of parsing String into NNn so it's 
easy to change formats?

Something based on using a list of parsers
[read, c43 . read, c43 . c23 . read, c43, c23 . c12 . read, c43 . c32 . 
c21 . read]


looks rather verbose and grows quadratically with N.

I'm sure there must be a more elegant way. Any ideas?

Dmitry

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] CBRef, a wrapper around IORef with callbacks

2010-12-14 Thread Dmitry V'yal

Hello,
	while building GUIs using Gtk2HS I always struggled with the following 
question: how to sync the state of the GUI with the state of the rest 
application. I usually make several IORefs store the state there. But 
it's quite easy to forget to update relevant parts of GUI when state 
changes, especially then it's done in several places, say, by user's 
request and by some internal event.


	Some time ago I realized a pattern which proved to be useful for me 
several times. I wrapped IORef in a type:


data CBRef a = CBRef {v_ref :: IORef a, callbacks :: IORef [a - IO()] }

now I add callbacks using

addCB :: CBRef a - (a - IO()) - IO ()
addCB r cb = modifyIORef (callbacks r) (++[cb])

which fires then the value is changed:

writeCBRef :: CBRef a - a - IO ()
writeCBRef r v = do
  writeIORef (v_ref r) v
  cbs - readIORef (callbacks r)
  mapM_ ($ v) cbs

all the remaining IORef-like interface is present too.

By using these callbacks for updating GUI I can be sure all it's parts 
are in sync.


I suspect it's a special case of more general idea. Can anyone give a hint?

Also, do you think it's useful enough to be uploaded to Hackage? Or 
maybe something similar is already there?


How do you organize your GUI applications?

Best wishes,
Dmitry

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Does it deserve to be a hackage package?

2010-10-28 Thread Dmitry V'yal

On 27.10.2010 13:16, Andy Stewart wrote:

Christopher Donechrisd...@googlemail.com  writes:


On 27 October 2010 10:13, Dmitry V'yalakam...@gmail.com  wrote:

While ago I had a question about opening the url in the default browser from
haskell program. I didn't get any immediate answers so I wrote my own
solution. On Linux it uses xdg-open and on Windows - ShellExecute Api.



Does it deserve to be a hackage package?


If it's not in an existing small library, yes. If I have to have a
dependency on gtk2hs just to do that, I'd rather have a small library.
Does it work on OS X? If not, I'm sure someone would submit a patch
for that. This can also be used for opening the file browser and such,
right?

It's APIs in GIO library (a sub-library in gtk2hs), you just need depend
on GIO don't need depend any other library.

Dmitry, it's unnecessary since GIO can do better with same experience
both Windows and Linux, don't need any external program help.
Infact, GIO not just call default browser for url, it can call any
program to open any format.


Ok then. I'll wait for it.
I hope binary package for Windows would be provided too. Currently I 
can't figure out how build gtk2hs there.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Does it deserve to be a hackage package?

2010-10-27 Thread Dmitry V'yal

Hello haskellers,

While ago I had a question about opening the url in the default browser 
from haskell program. I didn't get any immediate answers so I wrote my 
own solution. On Linux it uses xdg-open and on Windows - ShellExecute Api.


Later I received a letter saying what similar functionality was recently 
implemented in trunk version of gtk2hs but is currently unavailable as 
binary package.


Code I wrote works quite well for my purposes and I copied it into 
several my programs. In order to make maintenance easier I recently 
thought about uploading it to hackage. But given a wast amount of 
half-dead packages with intersecting functionality there I'd like to ask 
the opinion of community. Does such library look helpful to you?


Dmitry
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Opening a gtk2hs link in default browser

2010-10-17 Thread Dmitry V'yal

Hello list,

I'm trying to make a clickable link in gtk2hs program. Clicking it 
should open an url in the default browser. Can I hope to find some 
portable solution in gtk2hs (it should work in linux and windows) or 
should I start searching platform specific ones, like /usr/bin/xdg-open 
or something?


Can any examples be found in existing haskell software?

Dmitry
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] a couple of cabal related questions

2010-10-12 Thread Dmitry V'yal

Hello,

recently I've cabalized my program and it brought some problems.

First of all, I made use of 'import Paths_package name' functionality 
to get the path of installed data files. It works great, but now I can 
no longer run my program in ghci because this module is auto-generated 
by cabal. I tried to supply my own. This way ghci works, but my stub 
module gets compiled into the binary in place of auto-generated. And 
things break again. What's the best way to overcome it?


And another question. I'd like to make my program output it's version 
string. Of course, I can hardcode it into sources, but I've already 
specified one in the cabal file. Is there any way to get it back in the 
run time?


Thanks,
Dmitry
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] a couple of cabal related questions

2010-10-12 Thread Dmitry V'yal

On 12.10.2010 13:45, Magnus Therning wrote:

On Tue, Oct 12, 2010 at 10:20, Dmitry V'yalakam...@gmail.com  wrote:

Hello,

recently I've cabalized my program and it brought some problems.

First of all, I made use of 'import Paths_package name' functionality to
get the path of installed data files. It works great, but now I can no
longer run my program in ghci because this module is auto-generated by
cabal. I tried to supply my own. This way ghci works, but my stub module
gets compiled into the binary in place of auto-generated. And things break
again. What's the best way to overcome it?


Create a file called .ghci in the directory where you run ghci and
make it contains something like this:

:set -idist/build/autogen


And another question. I'd like to make my program output it's version
string. Of course, I can hardcode it into sources, but I've already
specified one in the cabal file. Is there any way to get it back in the run
time?


It's in Paths_package name  as the variable 'version'.

/M



That's perfectly what I was looking for, thanks a lot!

By the way, the 'version' variable doesn't mentioned in Cabal user 
guide, or at least I missed it. Is it documented somewhere?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Packaging a Gtk2hs based program for Windows

2010-10-07 Thread Dmitry V'yal

Hello, haskellers.

Recently I stumbled upon a problem. It may sound quite off-topic for 
this list, but, I'm sure, almost every haskell programmer runs into it 
sooner or later.


It sounds: How to make a neat Windows installer for a nice Gtk2hs 
program I wrote last week? How to solve the problem of dependency on 
GTK? Should I ask my users to install a GTK package or it would be 
better to package all the dynamic libraries needed along with my 
program? Are there any troubles with different character encodings used 
in Windows? How to change the application icon? And so on..


I understand, there is no ultimate answer, but I hope there is some 
wisdom to share. I've been a Linux user for more then five years and now 
I've found myself completely illiterate on how to make my code easily 
accessible for a nontechnical Windows user.


I would appreciate any thoughts and advises

Best wishes,
Dmitry
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Spiking neural networks in Haskell

2010-07-03 Thread Dmitry V'yal

Greetings anyone,

Some time ago I with a friend of mine implemented a toy interactive 
simulator of neural network activity. It has a totally imperative design 
and uses Gtk2hs for user interface parts.


The darcs repository is available here:
http://vyal.ru/code/spiking_neuro

Now we decided to develop it further to try out some nice biologically 
inspired ideas.


At first I wanted to rewrite the simulator in C++, since that language 
seems to match the current design more closely. But recently I've read 
some FRP related papers and have decided to rethink the overall approach.


I'd like to hear some comments from the community on the current code 
and advises on possible improvements and other designs and their pros 
and conses.


The performance is not critical for me, I'm looking for maximal 
flexibility and clearness so the model can easily be modified and extended.


Best wishes,
Dmitry
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Happstack basic question

2010-03-11 Thread Dmitry V'yal

Hello haskellers,

I want to host a simple happstack application behind a reverse proxy. So 
ideally would be to bind it to localhost only.


According to
http://hackage.haskell.org/packages/archive/happstack-server/0.4.1/doc/html/Happstack-Server-HTTP-Types.html#t%3AConf
Conf datatyle has only Port field. Does it mean, there is currently no 
way to prevent binding happstack to all available interfaces?


Regards,
Dmitry
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] GUI and background processing

2009-06-01 Thread Dmitry V'yal

Greetings, fellow haskellers.

Currently I'm writing some kind of web crawler in haskell with gtk2hs gui.

All network operations are run in separate thread, but sometimes input 
from user is needed. Afaik, gtk2hs is not thread safe, so I came up with 
following:


I create two mvars, A and B, one for question, one for answer. Worker 
thread puts question in A and blocks trying to take B. Gui thread checks 
for question by polling with tryTakeMVar. Then question is ready, it 
asks user and puts his answer into B. Worker awakens and continues 
processing.


Also, for progress report, I use a Chan which is written to by worker 
and is read by polling by gui thread.


This scheme works, but I don't like it. All these mvars and chans create 
too much clutter, and polling looks rather ugly too. Is there a better 
way for implementing similar patterns of interaction?


Best regards,
Dmitry.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to get glyph outline from ttf font.

2009-04-04 Thread Dmitry V'yal
	Greetings. I'm trying to render some glyphs from ttf font to svg image using 
gtk2hs cairo binding. Since I can find nothing appropriate in gtk2hs API,  I 
decided to draw outlines with bezier curves myself. But how to get them out of 
font? As far as I know, freetype library is capable of extracting outlines, but 
is there any haskell binding for it which supports this functionality?


	Here [1] one such lib was mentioned, but it wasn't availible online that time. 
Have situation changed today?


Thanks in advance

[1] 
http://www.nabble.com/Re%3A-Rendering-TTF-fonts-in-Haskell-and-OpenGL-p15635659.html

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] what GUI library should i select?

2006-11-14 Thread Dmitry V'yal
Iván Pérez Domínguez wrote:

 I'm using Gentoo Linux. We obviously don't use prebuilt packaged
 versions, but installing it is just doing emerge wxhaskell and
 'playing the... waiting game'. Gtk2hs support under Gentoo is mostly
 missing (the package is included, but doesn't work at all).

Hmm, that strange. I emerged both gtk2hs-0.9.10 and ghc-6.4.2 just fine.
Probably you should update your portage tree. I don't remember exactly, but I
used portage snapshot from late spring of 2006.

Now I'm waiting for ghc-6.6 being added to official portage tree.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] what GUI library should i select?

2006-11-14 Thread Dmitry V'yal
Bulat Ziganshin wrote:

 it is what i say about. threaded RTS + multipls threads that does
 computations + one thread that interfaces with Gtk2Hs. afaiu, the only
 problem is that i need to manage both Gtk events and periodically
 check queue of commands from other threads, but using timer + Chan
 should allow to implement this
 
I wrote multi threaded gui application in Haskell last spring as a educational
project. That was a tool for analyzing and extracting contents of FAT volumes.
Then i started my project, i was completely unaware of these threading 
issues
and freely called gtk2hs routines from several threads. All worked fine at
first, but when i added some disk I/O to my threads, my program became unstable.
While on linux it just crashed from time to time, on windows i saw more curious
behavior. At random spots threads lost ability to call WinAPI functions.
Basically they got an error code meaning something weird like insufficient
memory to complete call in return. That was not easily reproducible and
depended on exact version of Windows. At some point my app was fully functional
on WinXP and didn't even start on Win2000.
I spent a lot of time trying to debug these issues and finally 
refactored my
program to make use of approach you describe.  Worked fine after that. All you
have to do is to choose appropriate timer interval, otherwise your app becomes
too jerky or CPU hungry.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] what GUI library should i select?

2006-11-14 Thread Dmitry V'yal
Duncan Coutts wrote:

 The problem at the moment with GUIs and GHC's threaded RTS is that there
 is now way to specify that all the Haskell threads that want to do GUI
 stuff must run on a single OS thread. It's not impossible to solve but
 it requires either more support from the RTS or it needs a totally
 different approach, perhaps using a Haskell-level threading GUI monad
 rather than the IO monad.

Looks interesting for me. It's not too haskellish imo, when one ends with 2/3 of
code being in the IO monad. Although situation probably gets better then more
complex algorithms for processing data involved.

Are there any attempts to fine grain allowed side effects using several monads?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Profiling Gtk2HS applications

2006-06-07 Thread Dmitry V'yal
Hello.

How can one profile a program which uses gtk2hs?
I get this:

$ ghc --make MainGui.hs -prof
Chasing modules from: MainGui.hs
Could not find module `Graphics.UI.Gtk.Mogul':
  use -v to see a list of the files searched for
  (imported from ./TreeViewHelpers.hs)

I tried to specify gtk2hs source path using -i option with no success.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] UTF-8 Strings and GHC

2006-05-25 Thread Dmitry V'yal
Hi, all.
I'm writing a GUI app using Haskell and Gtk2HS. All goes well besides one thing.
I need to display some messages in russian and I can't figure out, how to handle
 that.

Gtk uses UTF-8 internally, so i have to pass UTF-8 strings to it somehow. But
how to define them in source file? I get lexical error in string/character
literal message then compiling using GHC-6.4.1.

I tried to bypass it by using koi8-r in sources and converting strings to UTF-8
on the fly using ffi binding to iconv I found in MissingH (iirc). Works fine on
Linux though is a little awkward, but I get wried results on Win32.

Is there any way to use unicode strings in sources?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] reading binary files

2006-04-07 Thread Dmitry V'yal
Hello, Bulat

I'm currently working on some kind of program for analysing FAT partitions.
Don't ask why did I chose to implement it in Haskell :)  Just for fun.
My program needs to read scattered chunks of binary data from a huge file and to
do a good amount of deserialisation.

I implemented basic functionality using Handles and Ptr's and now I'm starting
to regret for it. I have some pieces of code like:

type PtrAdvancer a b = StateT (Ptr a) IO b

peek_one :: Storable b = PtrAdvancer a b
peek_one = do
  p - get
  res - lift $ peek $ castPtr p
  put $ plusPtr p $ sizeOf res
  return res

peek_many :: Storable b = Int - PtrAdvancer a [b]
peek_many 0 = return []
peek_many n = do
  first - peek_one
  rest - peek_many $ n-1
  return $ first:rest


data DirEntry = DirEntry
{ name :: String,
  attr :: Word8,
  crt_time_tenth :: Word8,
  crt_time :: Word16,
  crt_data :: Word16,
  lst_acc_data :: Word16,
  wrt_time :: Word16,
  wrt_date :: Word16,
  fst_cluster :: Word32,
  file_size :: Word32
} deriving Show

instance Storable DirEntry where
sizeOf _ = 32
alignment _ = 32
peek = evalStateT peek_dir_entry

peek_dir_entry = do
  n - peek_many 11 :: PtrAdvancer a [Word8]
  at - peek_one
  peek_one :: PtrAdvancer a Word8
  ctt - peek_one
  ct - peek_one
  cd - peek_one
  lad - peek_one
  fch - peek_one :: PtrAdvancer a Word16
  wt - peek_one
  wd - peek_one
  fcl - peek_one :: PtrAdvancer a Word16
  fs - peek_one
  return $ DirEntry (words_to_str n) at ctt ct cd lad wt wd
 ((fromIntegral fch `shiftL` 16) + fromIntegral fcl) fs

or:

read_cluster_chain32 :: Handle - FatAddress - Cluster - IO [Cluster]
read_cluster_chain32 h start cluster = do
  allocaBytes 4 $ \p - chain32' p cluster True
  where
chain32' p c need_seek = do
  when need_seek $ hSeek h AbsoluteSeek (fromIntegral $ start + c * 4)
  hGetBuf h p 4
  val - peek p :: IO Word32
  let val28 = val .. 0x0fff
  case val28 of
0x0 - return []
0x0fff - return [c]
otherwise - do rest - if c+1 == val28 then chain32' p val28 False
 else  chain32' p val28 True
return $ c:rest

It works with a mediocre speed (about 10Mb/s when extracting files), but design
is ugly IMO. For example I need to write twice as much number of lines of
marshalling code compared to C. For data type declaration and then for Storable
instance. Is there a way to avoid it?


 with my lib, you can either read data directly from file (through
 implicit 512-byte buffer) or read whole file into the automatically
 allocated buffer with `readFromFile`. what is better - depends on what
 you plan to do with rest of file


Now I'm going to rewrite my code to make use of io library. So my question is
whether your library is well suited for such application (frequent positioning
and reading small pieces of data).

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GUI-Woes

2006-03-14 Thread Dmitry V'yal
Duncan Coutts wrote:
 You didn't do anything wrong. By default that's what happens with large
 libs built with ghc.
 
 However, the current development version (and so the next release
 version) of Gtk2Hs has support for ghc's split objects feature. With
 this, a simple Gtk2Hs Hello world program is only 30% larger than a
 trivial Haskell hello world program (main = putStr Hello World!).
 
 Duncan
 

Then I'm waiting impatiently for the next release.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GUI-Woes

2006-03-13 Thread Dmitry V'yal
Christophe Poucet wrote:
 I have to concur with Duncan.
 
 I started using Gtk2Hs for a small project and literally within a couple
 hours I had a good understanding upon which to build a nice gui as well as
 the gui itself.  I haven't tried out wxhaskell, but trying gtk2hs and it's
 cairo bindings, I fell in love with the simplicity.
 
 Cheers
 

I like gtk2hs too. I used it to make gui for my several toy projects. My
experience was mostly positive, but I had some troubles:
First of all, it's just a binding to GTK+, so if you don't have an 
expirience
with it (as in my case), you have to learn both GTK+ and gtk2hs simultaneously.
Secondly, I'm absolutely not satisfied with a size of produced 
binaries. I
hope, I just made something wrong, but I got a 3 megabyte behemot after
compiling and stripping my 300-line program. I compiled it with ghc-6.4.1 with
ghc --make Main.hs. objdump -T shows a myriad of symbols with gtk_ prefix and
I have a hard time guessing what most of them are doing where :)

I haven't looked at wxhaskell yet. Personally I don't like wxWidgets because
  of it's overall orientation on GDI API and resemblance with MFC. What is about
size of binaries produced using it?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Lists of Lists

2006-03-09 Thread Dmitry V'yal
zell_ffhut ?:
 Last attempt, as its due in a couple of hours
 
 Here's what i have so far..
 
 charToGrid :: Char - Position - Grid - Grid
 charToGrid c [] (row,col) xs = xs
 charToGrid c (row,col) xs = (changeValue c (concat xs (row*9 + col)))
 
 Using changeValue - 
 
 changeValue x 0 (y:ys) = (x:ys) 
 changeValue x n (y:ys) = y:(changeValue x (n-1) ys)
 
 Would really appritiate any help
 --
 View this message in context: 
 http://www.nabble.com/Lists-of-Lists-t1245394.html#a3315187
 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 

You can easily do it using updateList as Robert Dockins proposed.

updateList :: (a - a) - Int - [a] - [a]
updateList f i l = begin ++ (f x : end)
  where (begin, x : end) = splitAt i l

changeGrid :: Char - (Int,Int) - Grid - Grid
changeGrid c (row,col) grid = updateList updateRow row grid
where updateRow l = updateList (const c) col l

Here we replace a row with a new one, using a helper function updateRow which,
given the row, changes one symbol at position col in it. updateList is used
twice here. First it's applied to outer list and then to inner one. It is
possible because of higher-order nature of updateList. It's behavior can be
changed by suppling an appropriate function f as it's first argument.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Infinite loop?

2006-02-19 Thread Dmitry V'yal
Barbier de Reuille Pierre wrote:
 And how can you, in Haskell, detect symbolic links ?
 
One can use System.Posix.Files.isSymbolicLink function for that purpose.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Concurrency question

2005-09-07 Thread Dmitry V'yal

Donald Bruce Stewart wrote:


Can I ask if just using a `seq` works as well? That was enough (now I
recall) for the watchdog code I posted earlier.

-- Don


In my case this doesn't work

timeout :: DeepSeq a = Int - IO a - IO (Maybe a)
timeout n t = do res - par_io timer thr  --timer
 return res
where thr = do res - t
   return $! Just res
  timer = do threadDelay $ n * 1000
 return Nothing

It's probably because resolve function has type
 resolve :: CNF - (Bool, [(Int,Int)])
So it should be sequenced deeper.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Concurrency question

2005-09-06 Thread Dmitry V'yal


I believe you're just observing lazy evaluation at work.  The IO 
computation that you're forking is (return $ resolve cnf).  `resolve` is 
a pure function.  Hence the forked computation succeeds immediately--and 
the thread terminates (successfully)--without evaluating (resolve cnf).  
It isn't until the case arm that begins Just (ans, stats) - that the 
result of (resolve cnf) is demanded and hence evaluation of (resolve 
cnf) begins.  But this is too late for the timeout to have the intended 
effect.


How to fix?  You need to demand (enough of) the result of (resolve cnf) 
before returning from the IO computation.  What enough of means 
depends on how `resolve` is written.  You may find the DeepSeq module I 
wrote (see 
http://www.mail-archive.com/haskell@haskell.org/msg15819.html) helpful.


Dean


I've just tried DeepSeq as you proposed.

timeout :: DeepSeq a = Int - IO a - IO (Maybe a)
timeout n t = do res - par_io timer thr  --timer
 return res
where thr = do res - t
   return $!! Just res
  timer = do threadDelay n
 return Nothing

All works perfectly now! From now I'll pay more attention to evaluation order.

Thank you for your help and attention.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe