[Haskell-cafe] IterIO: How to write use my inumReverse

2011-07-04 Thread John Ky
Hi Haskell Cafe, I've defined the following reverse echo server that echos text back in reverse: module Programs.TcpEchoIterServer where import Control.Concurrent import Control.Exception import Control.Monad import Control.Monad.Trans import Data.IterIO import Data.IterIO.Inum import Network

Re: [Haskell-cafe] Confused about my IterIO code

2011-07-03 Thread John Ky
- atEOFI unless eof $ do line - lineI ifeed (L.concat [L.reverse line, C.pack \n]) loop Cheers, -John On 1 July 2011 01:20, dm-list-haskell-c...@scs.stanford.edu wrote: At Thu, 30 Jun 2011 23:53:02 +1000, John Ky wrote: But all I've done is: enum

[Haskell-cafe] Confused about my IterIO code

2011-06-30 Thread John Ky
Hi Hakell Cafe, I'm struggling to understand my unambitious IterIO code that somehow manages to work. Basically I run an echo server that is supposed to read from a socket line by line and write back to the socket with all the characters in the line reversed: import Control.Exception import

Re: [Haskell-cafe] IterIO type restricted functions

2011-06-29 Thread John Ky
Hi David, Good point. Not too fussed, though now that I think about it, I would have preferred it if enumFile' was defined in the tutorial rather than in the module. Cheers, -John On 29 June 2011 13:53, dm-list-haskell-c...@scs.stanford.edu wrote: At Wed, 29 Jun 2011 10:11:26 +1000, John

[Haskell-cafe] How to flush with IterIO in echo server

2011-06-29 Thread John Ky
Hi Haskell Cafe, I've written an echo server using just sockets: import Control.Concurrent import Control.Exception import Control.Monad import Network import Offsync.Data import System.IO import System.IO.Error (isEOFError) main = withSocketsDo $ do sListen - listenOn (PortNumber 8000)

[Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread John Ky
Hi all, I'm practising my Haskell by writing a simple TCP echo server and finding that getting my program control to be succinct is rather tricky. In particular, I have return () everywhere, my error handling is verbose and I'm not entirely sure my recursion is the cleanest way syntactically to

Re: [Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread John Ky
Hi Eric, Ivan, On 28 June 2011 18:32, Erik de Castro Lopo mle...@mega-nerd.com wrote: The hlint program would have flagged both of those and possibly others. See: Cool! It didn't flag either for me, but it recommended replacing ++ (show port)with ++ show port, if then else with unless,

Re: [Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread John Ky
June 2011 12:58, John Ky newho...@gmail.com wrote: Hi Eric, Ivan, On 28 June 2011 18:32, Erik de Castro Lopo mle...@mega-nerd.com wrote: The hlint program would have flagged both of those and possibly others. See: Cool! It didn't flag either for me, but it recommended replacing

[Haskell-cafe] IterIO type restricted functions

2011-06-28 Thread John Ky
Hi all, From the IterIO tutorial: enumFile' is like enumFile above, but type restricted to data in the lazy ByteString format, which is more efficient than plain Strings. (enumFile supports multiple types, but in this example there is not enough information for Haskell to choose one of them, so

Re: [Haskell-cafe] Getting library documentation for installed packages on Windows

2011-06-22 Thread John Ky
: John, Run `ghci`, then :m System.Directory getAppUserDataDirectory cabal That'll show you the directory where your cabal config is. On Jun 21, 2011, at 9:03 PM, John Ky wrote: Hi Svein, Where can I find this file on Windows 7 or Windows generally if its all the same

[Haskell-cafe] Getting library documentation for installed packages on Windows

2011-06-21 Thread John Ky
Hi all, Lately I've been finding the Network module missing from the docs I download from the GHC website, which brings me to the question: Is there any way I could generate libraries for this, the core libraries and all installed cabal packages into one reference so I can work offline? Cheers,

Re: [Haskell-cafe] Getting library documentation for installed packages on Windows

2011-06-21 Thread John Ky
options should be fairly obvious in there. On Jun 22, 2011 12:52 AM, John Ky newho...@gmail.com wrote: Hi all, Lately I've been finding the Network module missing from the docs I download from the GHC website, which brings me to the question: Is there any way I could generate libraries

Re: [Haskell-cafe] What's the advantage of writing Haskell this way?

2011-05-31 Thread John Ky
Thanks Malcom. I suspected that much, so I added it: data Stream m a = Chunks (m a) | EOF deriving (Show, Eq) instance (Monad m, MonadPlus m, Monoid (m a)) = Monoid (Stream m a) where mempty = Chunks mempty mappend (Chunks xs) (Chunks ys) = Chunks (xs `mappend` ys) mappend _ _ = EOF instance

[Haskell-cafe] What's the advantage of writing Haskell this way?

2011-05-30 Thread John Ky
Hi all, I'm trying to learn about enumerators by reading this paperhttps://john-millikin.com/downloads/enumerator_0.4.10.pdfand came across some code on page 2 that I found hard to digest, but I think I finally got it: import Data.Monoid data Stream a = Chunks [a] | EOF deriving (Show, Eq)

Re: [Haskell-cafe] What's the advantage of writing Haskell this way?

2011-05-30 Thread John Ky
...@yahoo.com wrote: From: John Ky newho...@gmail.com Sent: Monday, May 30, 2011 8:01 AM Hi all, I'm trying to learn about enumerators by reading this paper and came across some code on page 2 that I found hard to digest, but I think I finally got it: Hi John. These programs should

[Haskell-cafe] Circular pure data structures?

2009-07-14 Thread John Ky
Hello, Is it possible to create a circular pure data structure in Haskell? For example: a :: Data let b = getNext a let c = getNext b c == a -- Gives True Thanks, -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Circular pure data structures?

2009-07-14 Thread John Ky
Hello, Actually, I wanted to be able to create a tree structure when I can navigate both leaf-ward and root-ward. I didn't actually care for equality. I think the tying the knot technique as mentioned by others is sufficient for this purpose. Cheers, -John On Wed, Jul 15, 2009 at 8:55 AM,

Re: [Haskell-cafe] Circular pure data structures?

2009-07-14 Thread John Ky
: Sufficient, but not good. Try zippers instead. On 15 Jul 2009, at 08:29, John Ky wrote: Hello, Actually, I wanted to be able to create a tree structure when I can navigate both leaf-ward and root-ward. I didn't actually care for equality. I think the tying the knot technique as mentioned

Re: [Haskell-cafe] Where can I get GHC for Solaris?

2009-07-08 Thread John Ky
. This program built for sparc-sun-solaris2.9 j...@sun05:~ $ uname -a SunOS sun05 5.9 Generic_118558-30 sun4u sparc SUNW,Sun-Fire-280R Thanks, -John On Wed, Jul 8, 2009 at 4:48 PM, Aycan iRiCAN aycan.iri...@core.gen.trwrote: Çar, 2009-07-08 tarihinde 09:55 +1000 saatinde, John Ky yazdı: Hi, I had

[Haskell-cafe] Where can I get GHC for Solaris?

2009-07-07 Thread John Ky
Hi, Anyone know where I can get the GHC compiler and libraries for Solaris?: SunOS sun05 5.9 Generic_118558-30 sun4u sparc SUNW,Sun-Fire-280R I tried to compile GHC myself and got the following error: $ ./configure --enable-hc-boot checking build system type... sparc-sun-solaris2.9 checking

Re: [Haskell-cafe] How to pretty print code efficiently

2009-07-05 Thread John Ky
Hi all, Thanks everyone for the help. The HughesPJ module works well for me. Cheers, -John On Mon, Jul 6, 2009 at 3:49 AM, Chris Eidhof ch...@eidhof.nl wrote: On 4 jul 2009, at 05:13, Alexander Dunlap wrote: On Fri, Jul 3, 2009 at 6:45 PM, John Kynewho...@gmail.com wrote: Hi,

[Haskell-cafe] How to pretty print code efficiently

2009-07-03 Thread John Ky
Hi, Currently I'm pretty printing code by building arrays of strings and calling indent. For example: instance JavaPrintableNamed AST.EnumeratedType where javaLinesNamed parentName (AST.EnumeratedType memberDefinitions) = [ public enum ++ asJavaId(parentName) , { ] ++

Re: [Haskell-cafe] Record initialise question (RESOLVED)

2009-06-06 Thread John Ky
On Fri, Jun 5, 2009 at 8:05 PM, Martijn van Steenbergen mart...@van.steenbergen.nl wrote: Hi John, John Ky wrote: full = do let myOrder = init -- [1] { item = Just init { itemId = Something } , operation = Just

[Haskell-cafe] Conversion from string to array

2009-06-06 Thread John Ky
Hi Haskell Cafe, I'm trying to send stuff over UDP. To do that, I've written a test program that sends strings across. That was fine, but I wanted to send binary data too. So I tried that only to find I am having difficulty putting together some binary data. For examples take the fromHex

[Haskell-cafe] Why are these record accesses ambiguous

2009-06-06 Thread John Ky
Hi Haskell Cafe, In the following code, I get an error saying Ambiguous occurrence `x'. Why can't Haskell work out which x to call based on the type of getA? Thanks -John #!/usr/bin/env runhaskell {-# LANGUAGE DisambiguateRecordFields #-} import A import B main = do let xx = getA

Re: [Haskell-cafe] Why are these record accesses ambiguous

2009-06-06 Thread John Ky
, Jun 6, 2009 at 1:48 AM, John Ky newho...@gmail.com wrote: Hi Haskell Cafe, In the following code, I get an error saying Ambiguous occurrence `x'. Why can't Haskell work out which x to call based on the type of getA? Thanks -John #!/usr/bin/env runhaskell {-# LANGUAGE

[Haskell-cafe] Record initialise question

2009-06-05 Thread John Ky
Hi all, I have some sample code: full = do let myOrder = initOrder { item = Just initItem { itemId = Something } , operation = Just Buy } putStrLn $ show myOrder return () This is just a test project,

[Haskell-cafe] Type families not as useful over functions

2009-02-12 Thread John Ky
Hi Haskell Cafe, I tried using type families over functions, but when I try it complains that the two lines marked conflict with each other. class Broadcast a where type Return a broadcast :: a - Return a instance Broadcast [a - r] where type Return [a - r] = a - [r] -- Conflict!

Re: [Haskell-cafe] Type families not as useful over functions

2009-02-12 Thread John Ky
fs |$| a |$| b ? On 13 Feb 2009, at 02:34, John Ky wrote: Hi Haskell Cafe, I tried using type families over functions, but when I try it complains that the two lines marked conflict with each other. class Broadcast a where type Return a broadcast :: a - Return a instance

Re: [Haskell-cafe] Type families not as useful over functions

2009-02-12 Thread John Ky
Hi Johnaton, Ah yes. That makes sense. Is there a way to define type r to be all types except functions? -John On Fri, Feb 13, 2009 at 10:44 AM, Jonathan Cast jonathancc...@fastmail.fmwrote: On Fri, 2009-02-13 at 10:34 +1100, John Ky wrote: Hi Haskell Cafe, I tried using type families

[Haskell-cafe] Writing a generic event handler

2009-02-11 Thread John Ky
Hi Haskell Cafe, I'm interested in writing some events and event handlers in Haskell. I already have a Loop data structure, and I intend to use it for this purpose: -- Create event tEvent - newLoop (return ()) -- Register event handlers tHandler1 - newLoop (putStrLn Handler1) tHandler2 -

[Haskell-cafe] Why does sleep not work?

2009-02-09 Thread John Ky
Hi Haskell Cafe, I wrote very short program to sleep for 5 seconds compiled with the -threaded option in ghc on the Mac OS X 1.5. I am finding that using the sleep function doesn't sleep at all, whereas using threadDelay does: main = do putStrLn Waiting for 5 seconds. threadDelay

Re: [Haskell-cafe] Why does sleep not work?

2009-02-09 Thread John Ky
On Tue, Feb 10, 2009 at 8:59 AM, Peter Verswyvelen bugf...@gmail.comwrote: Hi John, Which sleep are you using? From which module? Can you show the full source with import statements? Cheers, Peter 2009/2/9 John Ky newho...@gmail.com Hi Haskell Cafe, I wrote very short program to sleep

Re: [Haskell-cafe] Type families are awesome

2009-01-27 Thread John Ky
Thanks Luke, Works great. On Wed, Jan 21, 2009 at 7:35 PM, Luke Palmer lrpal...@gmail.com wrote: 2009/1/21 John Ky newho...@gmail.com *Main let x = lookup *Main let y = Fx.Data.Map.lookup interactive:1:8: Ambiguous type variable `ma' in the constraint: `Fx.Data.Map.MapType ma

[Haskell-cafe] Type families are awesome

2009-01-21 Thread John Ky
Hi Haskell Cafe, I'm finding that I really like type families. For instance, the GHC.List.lookup and Data.Map.lookup functions annoy me because their names clash, yet their type are so similar. With type families, I could define a more generic lookup function like this: import Data.Map as MAP

[Haskell-cafe] Different return type?

2009-01-18 Thread John Ky
Hi, Possibly a silly question but is it possible to have a function that has a different return type based on it's first argument? For instance data Person = Person { name :: String, ... } data Business = Business { business_number :: Int, ...} key person = name person key business =

Re: [Haskell-cafe] Different return type?

2009-01-18 Thread John Ky
Hi Daniel, When would I use either? What are the trade-offs? Thanks -John On Mon, Jan 19, 2009 at 1:13 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Montag, 19. Januar 2009 02:44 schrieb John Ky: Hi, Possibly a silly question but is it possible to have a function that has

[Haskell-cafe] Debugging STM

2009-01-08 Thread John Ky
Hi, Does anyone have any advice on how to inspect complex TVar data structures that may include cycles? They're opaque as far as Show goes. And sometimes I'd like a more comprehensive view of my data structures at the ghci prompt rather than the dribs and drabs I get by typing x - atomically $

Re: [Haskell-cafe] Re: Tying a simple circularly STM linked list

2009-01-07 Thread John Ky
Thanks Chris, The undefined works for me. -John On Wed, Jan 7, 2009 at 11:11 AM, ChrisK hask...@list.mightyreason.comwrote: You can use undefined or error ... : {-# LANGUAGE RecursiveDo #-} import Control.Concurrent.STM import Control.Monad.Fix -- Transactional loop. A loop is a

[Haskell-cafe] Tying a simple circularly STM linked list

2009-01-06 Thread John Ky
Hi, I've written a circularly linked list, but there is some code in it I feel is redundant, but don't know how to get rid of: -- Transactional loop. A loop is a circular link list. data Loop a = ItemLink { item :: a , prev :: TVar (Loop a) , next :: TVar (Loop a) }

[Haskell-cafe] Transactional container for storing anonymous deletable objects

2008-12-28 Thread John Ky
Hi, I need a container data structure for storing anonymous objects - most likely things that have not value such as STM (), but probably other things as well. This will allow me to later on, iterate over the container and process those objects. Additionally I have the requirement that I need

[Haskell-cafe] Data.Map add only if not exist and return true if added

2008-12-09 Thread John Ky
Hi, I'm looking for a function for Data.Map that will insert a new key and value into the map if the key doesn't already exist in the map. When the key already exists, I don't want the value updated in the map. Additionally, I want to know whether the key/value was inserted or not so that I can

[Haskell-cafe] Deriving something else?

2008-12-08 Thread John Ky
Hi, I've defined a class and some instances, which I'm hoping would help me show values of types that may include transactional elements. class TShow a where tshow :: a - IO String instance Show (TVar a) where show = % instance (Show a) = TShow a where tshow a = return $ show a

[Haskell-cafe] Overlapping instances

2008-12-08 Thread John Ky
Hi, I've got the following code which tries to implement a TShow class, which is equivalent to Show, except it is supposed to work on TVar types as well. import GHC.Conc createEngine :: String - Int - Int - IO Engine createEngine name major minor = do tUsers - newTVarIO [] return $ Engine

[Haskell-cafe] Reading showables

2008-12-07 Thread John Ky
Hi, Is there a way to read Showables? main = do putStrLn $ show $ read Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Reading showables

2008-12-07 Thread John Ky
there is both read and show they are not inverses. Thomas. main = show . read Am 7. Dezember 2008 14:11 schrieb John Ky [EMAIL PROTECTED]: Hi, Is there a way to read Showables? main = do putStrLn $ show $ read Thanks -John

[Haskell-cafe] Is unsafePerformIO safe here?

2008-12-07 Thread John Ky
Hi, Is the following safe? moo :: TVar Int moo = unsafePerformIO $ newTVarIO 1 I'm interested in writing a stateful application, and I wanted to start with writing some IO functions that did stuff on some state and then test them over long periods of time in GHCi. I was worried I might be

Re: [Haskell-cafe] Reading showables

2008-12-07 Thread John Ky
: no parse -John On Mon, Dec 8, 2008 at 12:08 PM, Jonathan Cast [EMAIL PROTECTED]wrote: On Mon, 2008-12-08 at 11:16 +1100, John Ky wrote: Hi Thomas, So show . read and \x - show (read x) are actually mean different things? No. Of course not. But there's no guarantee that show

Re: [Haskell-cafe] Is unsafePerformIO safe here?

2008-12-07 Thread John Ky
:51 AM, Thomas Davie [EMAIL PROTECTED] wrote: On 8 Dec 2008, at 01:28, John Ky wrote: Hi, Is the following safe? moo :: TVar Int moo = unsafePerformIO $ newTVarIO 1 I'm interested in writing a stateful application, and I wanted to start with writing some IO functions that did stuff

Re: [Haskell-cafe] Is unsafePerformIO safe here?

2008-12-07 Thread John Ky
Inline. On Mon, Dec 8, 2008 at 1:28 PM, Luke Palmer [EMAIL PROTECTED] wrote: 2008/12/7 John Ky [EMAIL PROTECTED] Does that mean there is no place to store state while running the interpreter and that I have to put the state elsewhere such as a file? I was hoping to avoid that as I'm only

[Haskell-cafe] What is this function?

2008-10-16 Thread John Ky
Hi, I've written this function here: scramble [] = [] scramble [x] = [[z] | z - scramble x] scramble (x:xs) = [(y:z)|y - scramble x, z - scramble xs] and (I think) it roughly does what I want it to: *Main scramble ([]::[Int]) [] *Main scramble ([1]::[Int]) [[1],[2]]

Re: [Haskell-cafe] What is this function? (RESOLVED)

2008-10-16 Thread John Ky
-} I was basically after exhaustively generating lots ASTs given a template AST with lots of leaf values changed. Thanks, -John On Thu, Oct 16, 2008 at 8:39 PM, Luke Palmer [EMAIL PROTECTED] wrote: 2008/10/16 John Ky [EMAIL PROTECTED]: Hi, I've written this function here: scramble

[Haskell-cafe] How to do a special kind of comment with the TokenParser

2008-07-09 Thread John Ky
Hi, TokenParser supports two kinds of comments, the multi-line comments (ie. {- -}) and the single line comments (ie. -- \n). The language I am trying to parse, however, has comments which are neither. The -- acts like a single line comment which extends to the end of the line usually, but can

Re: [Haskell-cafe] GHC throws IOError on Win32 when there is no console

2007-02-11 Thread John Ky
Hi Paul, Can I have your code that doesn't work? I want to fiddle with it a bit. Thanks -John On 2/12/07, Paul Moore [EMAIL PROTECTED] wrote: On 09/02/07, Paul Moore [EMAIL PROTECTED] wrote: It probably wouldn't be hard to write a reasonably general wrapper for this, but it's a bit late

Re: [Haskell-cafe] GHC throws IOError on Win32 when there is no console

2007-02-10 Thread John Ky
Hi Duncan, Thanks for your comments. In the context of a haskell process running as a Windows service, a message box is useless, because Haskell services do not have a GUI and cannot interact with the desktop. -John ___ Haskell-Cafe mailing list

[Haskell-cafe] GHC throws IOError on Win32 when there is no console

2007-02-09 Thread John Ky
Hi, I noticed on Windows that when I use IO functions that write to stdout when the process is lacking a console, those functions throw an IOError. I'm not sure if this also occurs for stderr because I haven't tried it. Some classes of processes are created without a console because they never

[Haskell-cafe] Re: GHC throws IOError on Win32 when there is no console

2007-02-09 Thread John Ky
Sorry, I should clarify. I am writing about applications compiled with GHC. -John On 2/10/07, John Ky [EMAIL PROTECTED] wrote: Hi, I noticed on Windows that when I use IO functions that write to stdout when the process is lacking a console, those functions throw an IOError. I'm not sure

[Haskell-cafe] A function callable from C

2007-02-05 Thread John Ky
Hi, The following code works: type ServiceMainClosure = DWORD - IO () foreign import ccall wrapper mkServiceMainClosure :: ServiceMainClosure - IO (FunPtr ServiceMainClosure) But the following doesn't: type ServiceMainClosure = DWORD - [String] - IO () foreign import ccall wrapper

Re: [Haskell-cafe] A function callable from C

2007-02-05 Thread John Ky
Hi Stefan, In that case, how do I marshall [String] to Ptr (Ptr CChar)? Thanks -John On 2/6/07, Stefan O'Rear [EMAIL PROTECTED] wrote: You have to use a type that C's tiny brain understains. IANAWP but I'm guessing you want: type ServiceMainClosure = DWORD - Ptr (Ptr CChar) - IO ()

Re: [Haskell-cafe] A function callable from C

2007-02-05 Thread John Ky
: On Tue, Feb 06, 2007 at 12:40:38PM +1100, John Ky wrote: Hi Stefan, In that case, how do I marshall [String] to Ptr (Ptr CChar)? look at Foreign.C.String and Foreign.Ptr service-002.rename_as_zip Description: Binary data ___ Haskell-Cafe mailing

[Haskell-cafe] Re: Win32 help please

2007-02-04 Thread John Ky
Hi, I tried as suggested: hsc2hs mywin32.hsc ghc -c -O -fffi mywin32.hs which allows me to use ghci. And if I add a main function, I can also do this: hsc2hs mywin32.hsc ghc -fffi mywin32.hs -package Win32 Thanks everyone for the help. -John

[Haskell-cafe] Boost equivalent

2007-02-01 Thread John Ky
Hi, Does the Haskell community have an equivalent to C++ community's Boost project with the aim of writing libraries for the eventual inclusion into Haskell? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Paths to tree

2007-01-30 Thread John Ky
of which to me is considerably harder. Thanks for the tip. -John On 1/29/07, Tomasz Zielonka [EMAIL PROTECTED] wrote: On Mon, Jan 29, 2007 at 10:10:47PM +1100, John Ky wrote: I've written some code and was wondering if there was a better way to write it in terms of readability, brevity

Re: [Haskell-cafe] Re: Paths to tree

2007-01-30 Thread John Ky
Hi apfelmus, Your code is fine, I like it. A minor hint is that mergeForest is a fold: mergeForest = foldr merge [] Also, we have prettyPrint = putStr . unlines . prettyPrint' $ forest Nice help on the simple things. I can't know, but it doesn't seem unreasonable that you intend to

[Haskell-cafe] Paths to tree

2007-01-29 Thread John Ky
Hi, I've written some code and was wondering if there was a better way to write it in terms of readability, brevity and/or efficiency. The function concerned is pathsToForest which takes a list of paths (ie. [[String]]) and converts it into a tree structure where the individual nodes are the

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-25 Thread John Ky
Let me try this option and see how I go. Thanks -John On 1/25/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: (b) I think you *can* do this with a class: class Node a where name :: a - String data Branch = Branch { brName :: String, ... } data Leaf = Leaf { lName :: String,

[Haskell-cafe] A function for Maybes

2007-01-25 Thread John Ky
Is there a built-in function that already does this? foo :: (a - b) - Maybe a - Maybe b foo f m | isNothing m = Nothing | otherwise = Just (f (fromJust m)) *Main foo (+2) (Just 3) Just 5 *Main foo (+2) Nothing Nothing If so what is it? If not, what should I call it? Thanks -John

Re: [Haskell-cafe] A function for Maybes (RESOLVED)

2007-01-25 Thread John Ky
Thanks -John On 1/26/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: On Jan 25, 2007, at 9:15 , John Ky wrote: Is there a built-in function that already does this? foo :: (a - b) - Maybe a - Maybe b foo f m | isNothing m = Nothing | otherwise = Just (f (fromJust m)) Nothing

[Haskell-cafe] Trouble understanding records and existential types

2007-01-24 Thread John Ky
Hi, A while back I asked about OO programming in Haskell and discovered existential types. I understood that existential types allowed me to write heterogeneous lists which seemed sufficient at the time. Now trying to combine those ideas with records: data AnyNode = forall a. Node a = AnyNode

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-24 Thread John Ky
On 1/25/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: I'm probably missing something, but: (a) Why not: data ANode = Branch { name :: String, description :: String, children :: [AnyNode] } | Leaf { name :: String, value :: String } -- this reuse is legal -- leaving Node

[Haskell-cafe] What does the withProcessHandle_ function do?

2007-01-15 Thread John Ky
I want to learn how to use FFI with Win32, so I'm looking through the GHC source code. I encountered the function terminateProcess :: ProcessHandle - IO () terminateProcess ph = do withProcessHandle_ ph $ \p_ - case p_ of ClosedHandle _ - return p_ OpenHandle h - do

Re: [Haskell-cafe] UDP client/server

2007-01-11 Thread John Ky
[a] [b] *** Exception: connect: failed (Cannot assign requested address (WSAEADDRNOTAVAI L)) Thanks -John On 1/12/07, Gregory Wright [EMAIL PROTECTED] wrote: Hi John, On Jan 11, 2007, at 10:35 AM, Gregory Wright wrote: Hi John, On Jan 11, 2007, at 1:58 AM, John Ky wrote: Hello, Does

Re: [Haskell-cafe] UDP client/server

2007-01-11 Thread John Ky
Nevermind, I just got the client to work: echoClient :: IO () echoClient = withSocketsDo $ do sock - socket AF_INET Datagram 0 n - sendTo sock hi (SockAddrInet echoPort 0x0107f) return () Thanks everyone for your help. -John On 1/12/07, John Ky [EMAIL PROTECTED] wrote:Hi

[Haskell-cafe] CTRL+C in ghci.exe

2007-01-11 Thread John Ky
Hi, Is it possible to use CTRL+C or equivalent to interrupt a computation or I/O and return to the ghci prompt? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] CTRL+C in ghci.exey

2007-01-11 Thread John Ky
,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307 ,308,309,3 Thanks -John On 1/12/07, Stefan O'Rear [EMAIL PROTECTED] wrote: On Fri, Jan 12, 2007 at 05:07:04PM +1100, John Ky wrote: Hi, Is it possible to use CTRL+C or equivalent to interrupt a computation or I/O and return to the ghci prompt

[Haskell-cafe] UDP client/server

2007-01-10 Thread John Ky
Hello, Does anyone know where I can find a simple UDP client/server written in Haskell? Something along the lines of an echo server would do. Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Re: Designing an object model in Haskell (RESOLVED)

2006-12-13 Thread John Ky
Hi all, I'm now using existential types. I avoided learning about them because the name sounded so highly technical and obscure it did not occur to me they could be related to OO. Thanks, -John On 12/7/06, John Ky [EMAIL PROTECTED] wrote: Hi, I've got an object model that I have

[Haskell-cafe] Designing an object model in Haskell

2006-12-07 Thread John Ky
Hi, I've got an object model that I have a difficult time conceptualising how it might look like in Haskell: class Element { } class Inline : Element { } class ParentInline : Inline { ListInline children; } class Bold : ParentInline { } class Underline : ParentInline { } class Link :

[Haskell-cafe] Testing non-exported functions using ghci

2006-11-13 Thread John Ky
Hello,I have modules that don't export some functions. Is there a way I can access them from ghci without exporting them?Thanks-John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

[Haskell-cafe] What is the best way to preserve the order of a list

2006-11-01 Thread John Ky
Hi,I have a list of entities. Each entity has a priority field and an order field. The priority field contain the input values to my algorithm, the order fields contain the output value of my algorithm. My algorithm needs to assign 1 to the order field of the entity with the lowest priority value,

Re: [Haskell-cafe] What is the best way to preserve the order of a list (RESOLVED)

2006-11-01 Thread John Ky
Thanks Stefan,-JohnOn 11/1/06, Stefan Holdermans [EMAIL PROTECTED] wrote: John, My question is, how do I preserve the ordering of entities in my list and still be able to assign the proper order values to each entity?Is there an efficient way to do this?How else might I improve my orderByPriority

[Haskell-cafe] Re: Best way to write endsWith (RESOLVED)

2006-10-22 Thread John Ky
something in Haskell can be so short.5. Operators really are awesome.-JohnOn 10/22/06, John Ky [EMAIL PROTECTED] wrote:Hello, I have this function here: endsWith :: Eq a = [a] - [a] - Bool endsWith suffix list | lengthDifference 0 = False | otherwise = (drop lengthDifference list) == suffix where

[Haskell-cafe] Best way to write endsWith

2006-10-21 Thread John Ky
Hello,I have this function here: endsWith :: Eq a = [a] - [a] - Bool endsWith suffix list | lengthDifference 0 = False | otherwise = (drop lengthDifference list) == suffix where lengthDifference = (length list) - (length suffix)Would this be the preferred function argument order? Or is the

[Haskell-cafe] Trying to write a TCP proxy

2006-09-20 Thread John Ky
Hello, I'm trying to use haskell to put together a TCP proxy I can put between my browser and my webserver. This is as far as I got. The webserver isn't returning my request: listen = withSocketsDo $ do putStrLn Listening... socket - listenOn $ PortNumber 8082 (handleToClient,

[Haskell-cafe] Re: Trying to write a TCP proxy

2006-09-20 Thread John Ky
Actually, it blocks on: putStrLn contents It even blocks if I replace it with: print $ length contents Is there some kind of magic happening here? -John On 9/20/06, John Ky [EMAIL PROTECTED] wrote: Hello, I'm trying to use haskell to put together a TCP proxy I can put between my

Re: [Haskell-cafe] Trying to write a TCP proxy

2006-09-20 Thread John Ky
Hi Bulat, Thanks. Yes it helps with an earlier implementation I wrote (below). But surely there must be a better way to write this. My code is way to verbose. -John --- doProxyServer handleToClient handleToServer = do eof - hIsEOF handleToServer if not eof then do ready -

Re: [Haskell-cafe] Re: Trying to write a TCP proxy

2006-09-20 Thread John Ky
Sep 2006, John Ky wrote: Actually, it blocks on: putStrLn contents It even blocks if I replace it with: print $ length contents Is there some kind of magic happening here? No, but you're trying to do magic - it can't get all of contents until the connection's dropped. -- [EMAIL