Search Results

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

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

  • Good Haskell coding standards

    - by Alexey Romanov
    Could someone provide a link to a good coding standard for Haskell? I've found this and this, but they are far from comprehensive. Not to mention that the HaskellWiki one includes such "gems" as "use classes with care" and "defining symbolic infix identifiers should be left to library writers only."

    Read the article

  • Why won't the following haskell code compile?

    - by voxcogitatio
    I'm in the process of writing a small lisp interpreter in haskell. In the process i defined this datatype, to get a less typed number; data Number = _Int Integer | _Rational Rational | _Float Double deriving(Eq,Show) Compiling this fails with the following error: ERROR "types.hs":16 - Syntax error in data type declaration (unexpected `|') Line 16 is the line w. the first '|' in the code above.

    Read the article

  • Infinite loop in haskell? (newbie)

    - by Mike
    I'm just learning Haskell. I thought this would produce a factorial function... (within ghci) Prelude let ft 0 = 1 Prelude let ft n = n * ft (n - 1) Prelude ft 5 (hangs indefinitely, until ^C). Can someone point me in the right direction? Thanks!

    Read the article

  • Haskell data serialization of some data implementing a common type class

    - by Evan
    Let's start with the following data A = A String deriving Show data B = B String deriving Show class X a where spooge :: a -> Q [ Some implementations of X for A and B ] Now let's say we have custom implementations of show and read, named show' and read' respectively which utilize Show as a serialization mechanism. I want show' and read' to have types show' :: X a => a -> String read' :: X a => String -> a So I can do things like f :: String -> [Q] f d = map (\x -> spooge $ read' x) d Where data could have been [show' (A "foo"), show' (B "bar")] In summary, I wanna serialize stuff of various types which share a common typeclass so I can call their separate implementations on the deserialized stuff automatically. Now, I realize you could write some template haskell which would generate a wrapper type, like data XWrap = AWrap A | BWrap B deriving (Show) and serialize the wrapped type which would guarantee that the type info would be stored with it, and that we'd be able to get ourselves back at least an XWrap... but is there a better way using haskell ninja-ery? EDIT Okay I need to be more application specific. This is an API. Users will define their As, and Bs and fs as they see fit. I don't ever want them hacking through the rest of the code updating their XWraps, or switches or anything. The most i'm willing to compromise is one list somewhere of all the A, B, etc. in some format. Why? Here's the application. A is "Download a file from an FTP server." B is "convert from flac to mp3". A contains username, password, port, etc. information. B contains file path information. A and B are Xs, and Xs shall be called "Tickets." Q is IO (). Spooge is runTicket. I want to read the tickets off into their relevant data types and then write generic code that will runTicket on the stuff read' from the stuff on disk. At some point I have to jam type information into the serialized data.

    Read the article

  • Implementing a very simple 'Wine Rating System' in Haskell

    - by Alex N
    Hello, I have just started learning Haskell and have got stumped on how to add a rating to a custom data type. The data type I'm using has a name, a year and a tuple (userName and their rating), it looks like: data Wine = Wine String Int [Rating] deriving (Eq,Ord,Show,Read) type Rating = (String, Int) I wanted to allow a user to rate a given wine from a database, stored as [Wine] but cant figure out how to to it. Any pointers or suggestions would be greatly appreciated! Thanks.

    Read the article

  • Haskell - interpreting a number

    - by Abstract
    I have a number 9877342931235. Using Haskell, I need to show it as: 987-734293-123-5 i've tried interspersing the list but of course that puts '-' between every digit. How would I do it to yield the actual result?

    Read the article

  • Haskell Tuple Size Limit

    - by SHiNKiROU
    Why I can't construct large tuples in Haskell? Why there's a tuple size limit? Prelude> (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) <interactive>:1:0: No instance for (Show (t, t1, t2, ... t23)) arising from a use of `print' at <interactive>:1:0-48 Possible fix: add an instance declaration for (Show (t, t1, t2, ... t23)) In a stmt of a 'do' expression: print it

    Read the article

  • Haskell Binary Tree Function (map)

    - by Bizarro
    How can i define a Haskell function which will apply a function to every value in a binary tree? So i know that it is similar to the map function - and that its type would be: mapT :: (a - b) - Tree a - Tree b but thats about it...

    Read the article

  • Haskell "Source reduction"

    - by Martin
    I'm revising for an upcoming Haskell exam and I don't understand one of the questions on a past paper. Google turns up nothing useful fst(x, y) = x square i = i * i i) Source reduce, using Haskells lazy evaluation, the expression: fst(square(3+4), square 8) ii) Source reduce, using strict evaluation, the same expression iii) State one advantage of lazy evaluation and one advantage of strict evaluation

    Read the article

  • Haskell -> After parsing how to work with strings

    - by bito08
    Hello after doing the parsing with a script in Haskell I got a file with the 'appearance' of lists of strings. However when I call the file content with the function getContents or hGetContents, ie, reading the contents I get something like: String with lines (schematically what I want is: "[" aaa "," bbb "" ccc "]" - ["aaa", "bbb" "ccc"]). I have tried with the read function but without results. I need to work with these lists of strings to concatenating them all in a single list. Thanks.

    Read the article

  • Does F# have an equivalent to Haskell's take?

    - by McMuttons
    In Haskell, there is a function "take n list" which returns the first n elements from a list. For example "sum (take 3 xs)" sums up the first three elements in the list xs. Does F# have an equivalent? I expected it to be one of the List-functions, but I can't spot anything that seems to match.

    Read the article

  • Newbie: understanding main and IO()

    - by user1640285
    While learning Haskell I am wondering when an IO action will be performed. In several places I found descriptions like this: "What’s special about I/O actions is that if they fall into the main function, they are performed." But in the following example, 'greet' never returns and therefore nothing should be printed. import Control.Monad main = greet greet = forever $ putStrLn "Hello World!" Or maybe I should ask: what does it mean to "fall into the main function"?

    Read the article

  • pointers in haskell???

    - by curioComp
    hi, do you know if are there pointers in haskell? -If yes, how do you use them? Are there any problems with them? And why aren't they popular? -If no, is there any reason for it? Please help us!! :) Thank you so much!!

    Read the article

  • Look up or insert new element to string list in Haskell

    - by nightscream
    So I want to have a function that takes a String and a list as an argument, and checks if that element is already on the list, if it is, returns the same list, if it isnt, adds it to the list and returns it, 'im a begginer with haskell so heres what I have tried with no sucess: check:: String ->[String] ->[String] check x [] = []++[x] check x (y:xs) | x==y = (y:xs) | otherwise = check x xs Can someone point me the way ? thks

    Read the article

  • Haskell Monad bind currying

    - by Chime
    I am currently in need of a bit of brain training and I found this article on Haskell and Monads I'm having trouble with exercise 7 re. Randomised function bind. To make the problem even simpler to experiment, I replaced the StdGen type with an unspecified type. So instead of... bind :: (a -> StdGen -> (b,StdGen)) -> (StdGen -> (a,StdGen)) -> (StdGen -> (b,StdGen)) I used... bind :: (a -> c -> (b,c)) -> (c -> (a,c)) -> (c -> (b,c)) and for the actual function impelemtation (just straight from the exercise) bind f x seed = let (x',seed') = x seed in f x' seed' and also 2 randomised functions to trial with: rndf1 :: (Num a, Num b) => a -> b -> (a,b) rndf1 a s = (a+1,s+1) rndf2 :: (Num a, Num b) => a -> b -> (a,b) rndf2 a s = (a+8,s+2) So with this in a Haskell compiler (ghci), I get... :t bind rndf2 bind rndf2 :: (Num a, Num c) => (c -> (a, c)) -> c -> (a, c) This matches the bind curried with rndf2 as the first parameter. But the thing I don't understand is how... :t bind rndf2 . rndf1 Suddenly gives bind rndf2 . rndf1 :: (Num a, Num c) => a -> c -> (a, c) This is the correct type of the composition that we are trying to produce because bind rndf2 . rndf1 Is a function that: takes the same parameter type(s) as rndf1 AND takes the return from rndf1 and pipes it as an input of rndf2 to return the same type as rndf2 rndf1 can take 2 parameters a -> c and rndf2 returns (a, c) so it matches that a composition of these function should have type: bind rndf2 . rndf1 :: (Num a, Num c) => a -> c -> (a, c) This does not match the naive type that I initially came up with for bind bind f :: (a -> b -> (c, d)) -> (c, d) -> (e, f) Here bind mythically takes a function that takes two parameters and produces a function that takes a tuple in order that the output from rndf1 can be fed into rndf2 why the bind function needs to be coded as it is Why the bind function does not have the naive type

    Read the article

  • SQL Server IO handling mechanism can be severely affected by high CPU usage

    - by sqlworkshops
    Are you using SSD or SAN / NAS based storage solution and sporadically observe SQL Server experiencing high IO wait times or from time to time your DAS / HDD becomes very slow according to SQL Server statistics? Read on… I need your help to up vote my connect item – https://connect.microsoft.com/SQLServer/feedback/details/744650/sql-server-io-handling-mechanism-can-be-severely-affected-by-high-cpu-usage. Instead of taking few seconds, queries could take minutes/hours to complete when CPU is busy.In SQL Server when a query / request needs to read data that is not in data cache or when the request has to write to disk, like transaction log records, the request / task will queue up the IO operation and wait for it to complete (task in suspended state, this wait time is the resource wait time). When the IO operation is complete, the task will be queued to run on the CPU. If the CPU is busy executing other tasks, this task will wait (task in runnable state) until other tasks in the queue either complete or get suspended due to waits or exhaust their quantum of 4ms (this is the signal wait time, which along with resource wait time will increase the overall wait time). When the CPU becomes free, the task will finally be run on the CPU (task in running state).The signal wait time can be up to 4ms per runnable task, this is by design. So if a CPU has 5 runnable tasks in the queue, then this query after the resource becomes available might wait up to a maximum of 5 X 4ms = 20ms in the runnable state (normally less as other tasks might not use the full quantum).In case the CPU usage is high, let’s say many CPU intensive queries are running on the instance, there is a possibility that the IO operations that are completed at the Hardware and Operating System level are not yet processed by SQL Server, keeping the task in the resource wait state for longer than necessary. In case of an SSD, the IO operation might even complete in less than a millisecond, but it might take SQL Server 100s of milliseconds, for instance, to process the completed IO operation. For example, let’s say you have a user inserting 500 rows in individual transactions. When the transaction log is on an SSD or battery backed up controller that has write cache enabled, all of these inserts will complete in 100 to 200ms. With a CPU intensive parallel query executing across all CPU cores, the same inserts might take minutes to complete. WRITELOG wait time will be very high in this case (both under sys.dm_io_virtual_file_stats and sys.dm_os_wait_stats). In addition you will notice a large number of WAITELOG waits since log records are written by LOG WRITER and hence very high signal_wait_time_ms leading to more query delays. However, Performance Monitor Counter, PhysicalDisk, Avg. Disk sec/Write will report very low latency times.Such delayed IO handling also occurs to read operations with artificially very high PAGEIOLATCH_SH wait time (with number of PAGEIOLATCH_SH waits remaining the same). This problem will manifest more and more as customers start using SSD based storage for SQL Server, since they drive the CPU usage to the limits with faster IOs. We have a few workarounds for specific scenarios, but we think Microsoft should resolve this issue at the product level. We have a connect item open – https://connect.microsoft.com/SQLServer/feedback/details/744650/sql-server-io-handling-mechanism-can-be-severely-affected-by-high-cpu-usage - (with example scripts) to reproduce this behavior, please up vote the item so the issue will be addressed by the SQL Server product team soon.Thanks for your help and best regards,Ramesh MeyyappanHome: www.sqlworkshops.comLinkedIn: http://at.linkedin.com/in/rmeyyappan

    Read the article

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