2010/7/15 Serguey Zefirov <[email protected]>:
> 2010/7/14 Sergey Mironov <[email protected]>:
>> Hi cafe! I have a question of C-to-Haskell type:)
>>
>> Imagine web application wich allows users to browse some shared
>> filesystem located at the server.
>> Application stores every users's position within that filesystem
>> (current directory or file).
>>
>> In C this can be implemented with the help of following data types:
>>
>> Any ideas?
>
> Use IORef. ;)
>
> PS
> MVar is better, actually.
>
Somehow I forgot about them:) Code will turn into something like
data TreeNodeData = File | Dir (IORef TreeNode)
data TreeNode = TreeNode {
next :: Maybe (IORef TreeNode),
prev :: Maybe (IORef TreeNode),
up :: Maybe (IORef TreeNode), -- missed it in original C example
payload :: TreeNodeData
}
data User = User {
position :: IORef TreeNode,
-- ...
}
It really should work! (we don't take multithreading issues into
account for now)
Slightly annoying thing is that 1-to-1 mapping from C to Haskell also
forces programmer to perform C-like low-level pointer linking.
--
Thanks,
Sergey
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe