haskell

haskell check for user input errors

Hello. Im writing app in haskell and I would like to know that is the best way to check if users input is ok for example is it int when Im asking for int or if its date when asking for well formed date ? Thanks for help ...

NILL value in haskell

Hello, I get input (x) from user, convert it to Int by let y = (read x)::Int and then I would like the function to behave in a special way if user gave nothing (empty string). -- In this place I would like to handle situation in which user -- gave empty string as argument -- this doesnt work :/ yearFilter [] y = True --This works fine...

maximize frame on startup in wxHaskell

Hello, How can I make window maximized on start with wxHaskell ? Thanks for help ...

dealing with IO vs pure code in haskell

I'm writing a shell script (my 1st non-example in haskell) which is supposed to list a directory, get every file size, do some string manipulation (pure code) and then rename some files. I'm not sure what i'm doing wrong, so 2 questions: How should i arrange the code in such program? I have a specific issue, i get the following error, ...

Outputing UTF-8 string on Mac OS's Terminal

I got a programm in haskell outputting utf-8 using the package utf8-string and using only the output functions of this package. I set the encoding of each file I write to this way : hSetEncoding myFile utf8 {- myFile may be stdout -} but when I try to output : alpha = [toEnum 0x03B1] {- α -} instead of the nice alpha letter I got ...

creating instance of labelled fields data type

How do I create an instance of a "labelled fields data type"? data InputData = InputData { events :: [Event], newResources :: [Resource] } myInputData :: InputData myInputData = ??? ...

Haskell - interpreting a number

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? ...

Haskell - mapping the odd placed values and the even placed values differently

Hey guys, is there an easy way. To take a list of numbers, say 123456. Then multiply the odd placed by three and the even placed by 1. i.e. (1 * 3) + (2 * 1) + (3 * 3) + (4*1) + (5*3) + (6*1) i was thinking the map function somewhere along the lines. But i don't know how to map *3 to just the odd placed values. Oh and if you could giv...

strange error in haskell about indentation of if-then-else

I have the following code: foo :: Int -> [String] -> [(FilePath, Integer)] -> IO Int foo _ [] _ = return 4 foo _ _ [] = return 5 foo n nameREs pretendentFilesWithSizes = do result <- (bar n (head nameREs) pretendentFilesWithSizes) if result == 0 then return 0 -- <========================================== here is the error else...

simple putStrLn in Haskell/Yampa with arrows syntax

i'm using Haskell with the Yampa FRP library which uses the arrows language extension. how can i do a simple putStrLn in a SF? mySF = proc x -> do y <- identity -< x*x putStrLn "Hello World!" ++ show y returnA -< y the arrow syntax complains about the expression not bein an arrow (of course), but even with arrows i get no...

ghci not loading function from file

In test.hs, I have: doubleMe x = x + x In ghci, I type: Prelude> :l test [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main> doubleMe 9 <interactive>:1:0: Not in scope: `doubleMe' *Main> Why? How to fix? ...

Preferred way to do locales in the Haskell Platform

The Haskell platform includes two obsolete libraries, old-time and old-locale. For old-time, it also includes the preferred alternative (namely time), but I can't figure out what the recommended alternative for old-locale is. Is this simply a shortcoming of the Platform as of now (version 2010.1.0.0), or something I've overlooked? ...

Why would an image (the Mandelbrot) be skewed and wrap around?

So I just wrote a little snippet to generate the Mandelbrot fractal and imagine my surprise when it came out all ugly and skewed (as you can see at the bottom). I'd appreciate a point in the direction of why this would even happen. It's a learning experience and I'm not looking for anyone to do it for me, but I'm kinda at a dead end debu...

explain largestDivisible code from the Learn You A Haskell for Great Good tutorial

largestDivisible :: (Integral a) => a largestDivisible = head (filter p [100000,99999..]) where p x = x `mod` 3829 == 0 If p x equals True, does head (filter p [100000,99999..]) become head (filter True) ? What list is being filtered for True? While this code is being run, what are p and x's values? ...

Is there a good way to QuickCheck Happstack.State methods?

I have a set of Happstack.State MACID methods that I want to test using QuickCheck, but I'm having trouble figuring out the most elegant way to accomplish that. The problems I'm running into are: The only way to evaluate an Ev monad computation is in the IO monad via query or update. There's no way to create a purely in-memory MACID s...

An unusual type signature

In Monads for natural language semantics, Chung-Chieh Shan shows how monads can be used to give a nicely uniform restatement of the standard accounts of some different kinds of natural language phenomena (interrogatives, focus, intensionality, and quantification). He defines two composition operations, A_M and A'_M, that are useful for t...

Experiences teaching or learning map/reduce/etc before recursion?

As far as I can see, the usual (and best in my opinion) order for teaching iterting constructs in functional programming with Scheme is to first teach recursion and maybe later get into things like map, reduce and all SRFI-1 procedures. This is probably, I guess, because with recursion the student has everything that's necessary for iter...

Haskell: variant of `show` that doesn't wrap String and Char in quotes

I'd like a variant of show (let's call it label) that acts just like show, except that it doesn't wrap Strings in " " or Chars in ' '. Examples: > label 5 "5" > label "hello" "hello" > label 'c' "c" I tried implementing this manually, but I ran into some walls. Here is what I tried: {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE U...

putStrLn, type Char does not match [Char]

I have an haskell problem. putStrLn is supposed to take a [Char], or a String, and even though it seems like I give that to mr Compiler, he still complains. *** Expression : putStrLn line *** Term : line *** Type : Char *** Does not match : [Char] The code that it refers to is this: getV::[[(Char,Float)]] -> I...

Type-conditional controls in Haskell

I'm going through the 99 Haskell problems to build my proficiency with the language. On problem 7 ("Flatten a nested list structure"), I found myself wanting to define a conditional behavior based on the type of argument passed to a function. That is, since *Main> :t 1 1 :: (Num t) => t *Main> :t [1,2] [1,2] :: (Num t) => [t] *Main> :...