Search Results

Search found 4547 results on 182 pages for 'haskell io'.

Page 6/182 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Filtering serial port io

    - by mr odus
    I am currently working on a project where I communicate with hardware via a com port on its respective pc(win xp or 7) It is a fairly large project and sifting through the log file can be a bit of pain. This is my current setup. I use putty to do the actual serial communication, and write it to a log file. Then using MinGW Msys I filter it using tail -f "puttyLog" | grep -i "search term" Is there a better way to do this? I mean specifically filtering the input in realtime. Not that mine is terrible, but it still involves having to read from a log and sometimes there have been hangups where it will be delayed for a minute or 2. I have used software in the past with a main io window and then internal filter panels, but can no longer remember or find it.

    Read the article

  • Possible disk IO issue

    - by Tim Meers
    I've been trying to really figure out what my IOPS are on my DB server array and see if it's just too much. The array is four 72.6gb 15k rpm drives in RAID 5. To calculate IOPS for RAID 5 the following formula is used: (reads + (4 * Writes)) / Number of disks = total IOPS. The formula is from MSDN. I also want to calculate the Avg Queue Length but I'm not sure where they are getting the formula from, but i think it reads on that page as avg que length/number of disks = actual queue. To populate that formula I used the perfmon to gather the needed information. I came up with this, under normal production load: (873.982 + (4 * 28.999)) / 4 = 247.495. Also the disk queue lengh of 14.454/4 = 3.614. So to the question, am I wrong in thinking this array has a very high disk IO? Edit I got the chance to review it again this morning under normal/high load. This time with even bigger numbers and IOPS in excess of 600 for about 5 minutes then it died down again. But I also took a look at the Avg sec/Transfer, %Disk Time, and %Idle Time. These number were taken when the reads/writes per sec were only 332.997/17.999 respectively. %Disk Time: 219.436 %Idle Time: 0.300 Avg Disk Queue Length: 2.194 Avg Disk sec/Transfer: 0.006 Pages/sec: 2927.802 % Processor Time: 21.877 Edit (again) Looks like I have that issue solved. Thanks for the help. Also for a pretty slick parser I found this: http://pal.codeplex.com/ It works pretty well for breaking down the data into something usable.

    Read the article

  • haskell: a data structure for storing ascending integers with a very fast lookup

    - by valya
    Hello! (This question is related to my previous question, or rather to my answer to it.) I want to store all qubes of natural numbers in a structure and look up specific integers to see if they are perfect cubes. For example, cubes = map (\x -> x*x*x) [1..] is_cube n = n == (head $ dropWhile (<n) cubes) It is much faster than calculating the cube root, but It has complexity of O(n^(1/3)) (am I right?). I think, using a more complex data structure would be better. For example, in C I could store a length of an already generated array (not list - for faster indexing) and do a binary search. It would be O(log n) with lower ?oefficient than in another answer to that question. The problem is, I can't express it in Haskell (and I don't think I should). Or I can use a hash function (like mod). But I think it would be much more memory consuming to have several lists (or a list of lists), and it won't lower the complexity of lookup (still O(n^(1/3))), only a coefficient. I thought about a kind of a tree, but without any clever ideas (sadly I've never studied CS). I think, the fact that all integers are ascending will make my tree ill-balanced for lookups. And I'm pretty sure this fact about ascending integers can be a great advantage for lookups, but I don't know how to use it properly (see my first solution which I can't express in Haskell).

    Read the article

  • io operations in compilers

    - by Aastha
    How are constructs of io operations handled by a compiler? Like the RTL mapping for memory related operations which is done in a compiler at the time of target code generation, where and how exactly is the same done for io operations? How are the appeoaches different for processors supporting MMIO and I/O mapped I/O? Are there any optimizations done for the io operations in compilers?

    Read the article

  • Haskell: monadic takeWhile?

    - by Mark Rushakoff
    I have some functions written in C that I call from Haskell. These functions return IO (CInt). Sometimes I want to run all of the functions regardless of what any of them return, and this is easy. For sake of example code, this is the general idea of what's happening currently: Prelude> let f x = print x >> return x Prelude> mapM_ f [0..5] 0 1 2 3 4 5 Prelude> I get my desired side effects, and I don't care about the results. But now I need to stop execution immediately after the first item that doesn't return my desired result. Let's say a return value of 4 or higher requires execution to stop - then what I want to do is this: Prelude> takeWhile (<4) $ mapM f [0..5] Which gives me this error: <interactive:1:22: Couldn't match expected type `[b]' against inferred type `IO a' In the first argument of `mapM', namely `f' In the second argument of `($)', namely `mapM f ([0 .. 5])' In the expression: takeWhile (< 4) $ mapM f ([0 .. 5]) And that makes sense to me - the result is still contained in the IO monad, and I can't just compare two values contained in the IO monad. I know this is precisely the purpose of monads -- chaining results together and discarding operations when a certain condition is met -- but is there an easy way to "wrap up" the IO monad in this case to stop executing the chain upon a condition of my choosing, without writing an instance of MonadPlus? Can I just "unlift" the values from f, for the purposes of the takeWhile? Is this a solution where functors fit? Functors haven't "clicked" with me yet, but I sort of have the impression that this might be a good situation to use them. Update: @sth has the closest answer to what I want - in fact, that's almost exactly what I was going for, but I'd still like to see whether there is a standard solution that isn't explicitly recursive -- this is Haskell, after all! Looking back on how I worded my question, now I can see that I wasn't clear enough about my desired behavior. The f function I used above for an example was merely an example. The real functions are written in C and used exclusively for their side effects. I can't use @Tom's suggestion of mapM_ f (takeWhile (&lt;4) [0..5]) because I have no idea whether any input will really result in success or failure until executed. I don't actually care about the returned list, either -- I just want to call the C functions until either the list is exhausted or the first C function returns a failure code. In C-style pseudocode, my behavior would be: do { result = function_with_side_effects(input_list[index++]); } while (result == success && index < max_index); So again, @sth's answer performs the exact behavior that I want, except that the results may (should?) be discarded. A dropWhileM_ function would be equivalent for my purposes. Why isn't there a function like that or takeWhileM_ in Control.Monad? I see that there was a similar discussion on a mailing list, but it appears that nothing has come of that.

    Read the article

  • Multi Player game using Nodejs and Socket IO

    - by Kishorevarma
    I am trying out multi player racing game using Node and Socket IO ,express . So I have tried simple example to see the latency between node server and the clients. I have a draggable image in client . when I move the image ienter code heren one client ,it has to move in all clients. so basically when I am moving the image I am sending the image position to the node server in a json format , then from there I am broadcasting to all clients. there is a ~approx 300ms latency from the time. following are the results. Client 1 sending data to server at : 286136 (timestamp) Server received at : 286271 Client2 received data at : 286470 Client3 received data at : 286479 Client4 received data at : 286487 Client5 received data at : 286520 the latency between move from client1 to client5 is 384ms. its too hight for a racing game .. here is my server code. var app = require('express').createServer(); var io = require('socket.io'); var http = require('http'); var http_server = http.createServer(); var server = http.createServer(app); server.listen(3000); var socket = io.listen(server,{ log: false }); socket.sockets.on('connection', function (client) { client.on('message', function (data){ console.log("data arrived to server",new Date().getTime()); // Below both statements are giving same latency between the client 1 and client 5 client.broadcast.emit('message',data); //socket.sockets.emit('message',data); }); }); 1) Is there any way to optimize the server code to reduce the latency? 2) is this expected latency using node and websockets ? 3) is socket io can't broadcast the data asynchronously (I mean at a same time) ? Thanks Kishorevarma

    Read the article

  • haskell network io hgetline

    - by Alex
    I want to read all the data on a handle, and then block waiting for more data. listen1 stops when there is a '\n' character in the stream. listen2 works and could be made completely general by imitating the code for hGetNonBlocking. What is the best way to do this? import qualified Data.ByteString as B loop = sequence_ . repeat listen1 :: Handle -> TChan B.ByteString -> IO() listen1 sock chan = do loop ( do s <- B.hGetLine sock atomically (writeTChan chan s) ) listen2 :: Handle -> TChan B.ByteString -> IO() listen2 sock chan = do loop ( do s <- B.hGet sock 1 s1 <- B.hGetNonBlocking sock 65000 atomically (writeTChan chan (B.append s s1)) )

    Read the article

  • Haskell IO Passes to Another Function

    - by peterwkc
    This question here is related to http://stackoverflow.com/questions/3066956/haskell-input-return-tuple I wonder how we can passes the input from monad IO to another function in order to do some computation. Actually what i want is something like -- First Example test = savefile investinput -- Second Example maxinvest :: a maxinvest = liftM maximuminvest maxinvestinput maxinvestinput :: IO() maxinvestinput = do str <- readFile "C:\\Invest.txt" let cont = words str let mytuple = converttuple cont let myint = getint mytuple putStrLn "" -- Convert to Tuple converttuple :: [String] -> [(String, Integer)] converttuple [] = [] converttuple (x:y:z) = (x, read y):converttuple z -- Get Integer getint :: [(String, Integer)] -> [Integer] getint [] = [] getint (x:xs) = snd (x) : getint xs -- Search Maximum Invest maximuminvest :: (Ord a) => [a] -> a maximuminvest [] = error "Empty Invest Amount List" maximuminvest [x] = x maximuminvest (x:xs) | x > maxTail = x | otherwise = maxTail where maxTail = maximuminvest xs In the second example, the maxinvestinput is read from file and convert the data to the type maximuminvest expected. Please help. Thanks.

    Read the article

  • Why isn't my IO executed in order?

    - by HaskellElephant
    Hi, I'm having some fun learning about the haskell IO. However in my recent exploration of it I have encountered some problems with IO not executing in order, even inside a do construct. In the following code I am just keeping track of what cards are left, where the card is a tuple of chars (one for suit and one for value) then the user is continously asked for wich cards have been played. I want the putStr to be executed between each input, and not at the very end like it is now. module Main where main = doLoop cards doLoop xs = do putStr $ show xs s <- getChar n <- getChar doLoop $ remove (s,n) xs suits = "SCDH" vals = "A23456789JQK" cards = [(s,n) | s <- suits, n <- vals] type Card = (Char,Char) remove :: Card -> [Card] -> [Card] remove card xs = filter (/= card) xs

    Read the article

  • Using Haskell's Parsec to parse binary files?

    - by me2
    Parsec is designed to parse textual information, but it occurs to me that Parsec could also be suitable to do binary file format parsing for complex formats that involve conditional segments, out-of-order segments, etc. Is there an ability to do this or a similar, alternative package that does this? If not, what is the best way in Haskell to parse binary file formats?

    Read the article

  • Turtle Graphics as a Haskell Monad

    - by iliis
    I'm trying to implement turtle graphis in Haskell. The goal is to be able to write a function like this: draw_something = do fordward 100 right 90 forward 100 ... and then have it produce a list of points (maybe with additional properties): > draw_something (0,0) 0 -- start at (0,0) facing east (0 degrees) [(0,0), (0,100), (-100,100), ...] I have all this working in a 'normal' way, but I fail to implement it as a Haskell Monad and use the do-notation. The basic code: data State a = State (a, a) a -- (x,y), angle deriving (Show, Eq) initstate :: State Float initstate = State (0.0,0.0) 0.0 -- constrain angles to 0 to 2*pi fmod :: Float -> Float fmod a | a >= 2*pi = fmod (a-2*pi) | a < 0 = fmod (a+2*pi) | otherwise = a forward :: Float -> State Float -> [State Float] forward d (State (x,y) angle) = [State (x + d * (sin angle), y + d * (cos angle)) angle] right :: Float -> State Float -> [State Float] right d (State pos angle) = [State pos (fmod (angle+d))] bind :: [State a] -> (State a -> [State a]) -> [State a] bind xs f = xs ++ (f (head $ reverse xs)) ret :: State a -> [State a] ret x = [x] With this I can now write > [initstate] `bind` (forward 100) `bind` (right (pi/2)) `bind` (forward 100) [State (0.0,0.0) 0.0,State (0.0,100.0) 0.0,State (0.0,100.0) 1.5707964,State (100.0,99.99999) 1.5707964] And get the expected result. However I fail to implement this as an instance of Monad. instance Monad [State] where ... results in `State' is not applied to enough type arguments Expected kind `*', but `State' has kind `* -> *' In the instance declaration for `Monad [State]' And if I wrap the list in a new object data StateList a = StateList [State a] instance Monad StateList where return x = StateList [x] I get Couldn't match type `a' with `State a' `a' is a rigid type variable bound by the type signature for return :: a -> StateList a at logo.hs:38:9 In the expression: x In the first argument of `StateList', namely `[x]' In the expression: StateList [x] I tried various other versions but I never got it to run as I'd like to. What am I doing wrong? What do I understand incorrectly?

    Read the article

  • optional arguments in haskell

    - by snorlaks
    Hello, I have declared my own type: data Book = Bookinfo { bookId :: Int, title :: String } deriving(Show) and now: x = Bookinfo it is all ok, valid statement but making bookId x throws an error. If I would be able to handle errors in Haskell that would be ok but right now I cant do this So Im curious how to make not specified values of fields take default value, and what exactly value is there when I'm not giving vcalues of fields in construcotr ? thanks for help

    Read the article

  • What does the >> symbol mean in Haskell.

    - by CharlesS
    I was reading the Guestbook example for Happstack and noticed the symbol which I didn't see before in the textbooks I studied to learn Haskell (for instance see line 23). What is it? Example I could not find it in Google because it ignores the totally (Bing does not but comes up with tons of non-related results). Thanks!

    Read the article

  • Simple haskell string manage

    - by paurullan
    Theres is a little problem I want to solve with Haskell: let substitute a function that change all of the wildcards in a string for one concrete parameter. The function has de signature of: subs :: String -> String -> String -> String -- example: -- subs 'x' "x^3 + x + sin(x)" "6.2" will generate -- "6.2^3 + 6.2 + sin(6.2)"

    Read the article

  • Creating Haskell instance declarations

    - by btl
    Hello, complete noob to Haskell here with probably an even noobier question. I'm trying to get ghci output working and am stuck on instance declarations. How could I declare an instance for "(Show (Stack - Stack))" given: data Cmd = LD Int | ADD | MULT | DUP deriving Show type Prog = [Cmd] type Stack = [Int] type D = Stack -> Stack I've been trying to create a declaration like: instance Show D where show = Stack but all my attempts have resulted in illegal instance declarations. Any help and/or references much appreciated!

    Read the article

  • Performance of looping over an Unboxed array in Haskell

    - by Joey Adams
    First of all, it's great. However, I came across a situation where my benchmarks turned up weird results. I am new to Haskell, and this is first time I've gotten my hands dirty with mutable arrays and Monads. The code below is based on this example. I wrote a generic monadic for function that takes numbers and a step function rather than a range (like forM_ does). I compared using my generic for function (Loop A) against embedding an equivalent recursive function (Loop B). Having Loop A is noticeably faster than having Loop B. Weirder, having both Loop A and B together is faster than having Loop B by itself (but slightly slower than Loop A by itself). Some possible explanations I can think of for the discrepancies. Note that these are just guesses: Something I haven't learned yet about how Haskell extracts results from monadic functions. Loop B faults the array in a less cache efficient manner than Loop A. Why? I made a dumb mistake; Loop A and Loop B are actually different. Note that in all 3 cases of having either or both Loop A and Loop B, the program produces the same output. Here is the code. I tested it with ghc -O2 for.hs using GHC version 6.10.4 . import Control.Monad import Control.Monad.ST import Data.Array.IArray import Data.Array.MArray import Data.Array.ST import Data.Array.Unboxed for :: (Num a, Ord a, Monad m) => a -> a -> (a -> a) -> (a -> m b) -> m () for start end step f = loop start where loop i | i <= end = do f i loop (step i) | otherwise = return () primesToNA :: Int -> UArray Int Bool primesToNA n = runSTUArray $ do a <- newArray (2,n) True :: ST s (STUArray s Int Bool) let sr = floor . (sqrt::Double->Double) . fromIntegral $ n+1 -- Loop A for 4 n (+ 2) $ \j -> writeArray a j False -- Loop B let f i | i <= n = do writeArray a i False f (i+2) | otherwise = return () in f 4 forM_ [3,5..sr] $ \i -> do si <- readArray a i when si $ forM_ [i*i,i*i+i+i..n] $ \j -> writeArray a j False return a primesTo :: Int -> [Int] primesTo n = [i | (i,p) <- assocs . primesToNA $ n, p] main = print $ primesTo 30000000

    Read the article

  • Understanding Haskell's filter

    - by dmindreader
    I understand that Haskell's filter is a high order function (meaning a function that takes another function as a parameter) that goes through a list checking which element fulfills certain boolean condition. I don't quite understand its definition: filter:: (a->Bool)->[a]->[a] filter p [] = [] filter p (x:y) | p x = x:filter p y | otherwise = filter p y I understand that if I pass an empty list to the function, it would just return an empty list, but how do I read the last two lines?

    Read the article

  • Control statements in Haskell?

    - by Nathan
    I am just beginning Haskell, but from all the online tutorials I've found I can't seem to find if there is one accepted way to do a conditional control statement. I have seen if-else, guards, and pattern matching, but they all seem to accomplish the same thing. Is there one generally accepted/faster/more efficient way than the rest?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >