Hi all,
I have a function like this:
selectValue1 :: Int -> [(Int,Int)] -> [Int]
selectValue1 a [(x,y)]= [ y |(x,y)<-[(x,y)],x<-(x,y),x==a ]
what i want to do is to pass a tuple list to the function and take the second item in the tuple if the first item in the tuple matches with the input a.But this function give me an error:
Type ...
Greetings,
I'm trying to understand why I'm seeing the entire file loaded into memory with the following program, yet if you comment out the line below "(***)" then the program runs in constant (about 1.5M) space.
EDIT: The file is about 660MB, the field in column 26 is a date string like '2009-10-01', and there are one million lines....
Both are terms whose type is the intersection of all types (uninhabited). Both can be passed around in code without failing until one attempts to evaluate them. The only difference I can see is that in Java, there is a loophole which allows null to be evaluated for exactly one operation, which is reference equality comparison (==)--where...
Given an arbitrary number, how can I process each digit of the number individually?
Edit
I've added a basic example of the kind of thing Foo might do.
For example, in C# I might do something like this:
static void Main(string[] args)
{
int number = 1234567890;
string numberAsString = number.ToString();
foreach(char x in ...
The program return all possible combinations of '0' and '1' length N.
addToElement :: String -> String -> String
addToElement element symbol = element ++ symbol
addOneToElement :: String -> String
addOneToElement element = addToElement element "1"
addZeroToElement :: String -> String
addZeroToElement element = addToEle...
Hi,
When working in the ocaml or ghci toplevels I often build up a significant "context" for want of a better word, values bound, functions, modules loaded, and so on. Is there a way to save all of that and reload it later so I can continue exactly where I left off? Or better yet, dump out the entire lot as a text file that could be rel...
This code works:
posToXY :: Float -> Float -> Integer
posToXY a b = do
let y = a / b
round y
But this doesn't work:
posToXY :: Integer -> Integer -> Integer
posToXY a b = do
let y = a / b
round y
I understand that operation '/' doesn't define for Integer type, but I don't know how to fix code to work...
The following program yields an error in ghci:
{-# LANGUAGE NoImplicitPrelude #-}
import Prelude (Integer, Bool)
import qualified Prelude
class Discrete a where
(==) :: a -> a -> Bool
instance Discrete Integer where
(==) = (Prelude.==)
class Monoid a where
one :: a
(*) :: a -> a -> a
fromInteger :: Integer -> a
...
I'm just wondering how $ works: I was expecting
> (flip (+).digitToInt) $ '4' 4
<interactive>:1:24:
Couldn't match expected type `t -> Char'
against inferred type `Char'
In the second argument of `($)', namely '4' 4
In the expression: (flip (+) . digitToInt) $ '4' 4
In the definition of `it': it = (flip (+) ...
Currently I am thinking and searching for the adequate programming languages for a project
(more than one programming language will be used).
Questions:
Is there a big mistake presented in my list (other than my belief of go as a suitable language)?
Any tipps before I start?
project:
opensource project with semantic web (including rdf/...
I'm reviewing Haskell: The Craft of Functional Programming, however the type signatures on page 356 have thrown me for a loop.
Here is a simple one:
succeed :: b -> Parse a b
succeed val inp = [( val, inp )]
How can that be b -> Parse a b, if
succeed Int -> Int
succeed a = a
and,
succeed Int -> Int -> Int
succeed a b = a + b
Th...
Hi
I have:
main :: IO ()
main = do
iniciofibonaccimap <- getCPUTime
let fibonaccimap = map fib listaVintesete
fimfibonaccimap <- getCPUTime
let difffibonaccimap = (fromIntegral (fimfibonaccimap - iniciofibonaccimap)) / (10^12)
printf "Computation time fibonaccimap: %0.3f sec\n" (difffibonaccimap :: Double)
lis...
Consider the following (Haskell) code:
fib=0:1:zipWith (+) fib (tail fib)
A coworker is trying to assert that this is not a recursive function because fib is simply a list that defines itself with itself and that is somehow different than a function that does the same. I think he's smoking crack.
What do you think?
...
As i understand Haskell does not have a global state, so is there any way to write a function f that will return f(n - 1) + 1, where n is a number of function call and f(1) = 0.
It should not accept any arguments and used like func f
Prelude> f ()
0
Prelude> f ()
1
...
I'm a newbie, and the monads get me totally confused. Given a list of filenames i'd like to know whether all the files exist.
Generally, i'd like to do:
import System.Directory
allFilesPresent files = foldr (&&) True (map doesFileExist files)
However i do not know what's the right way to do it, because there's IO Bool instead of Bool...
I have a search tree thats defined as
data (Ord a) => Stree a = Null | Fork(Stree a) a (Stree a) deriving Show
and I have to define two functions, mapStree:
mapStree :: (Ord b, Ord a) => (a -> b) -> Stree a -> Stree b
and foldStree:
foldStree :: (Ord a) => (b -> a -> b -> b) -> b -> Stree a -> b
I dont fully understand whats g...
I need a function that works like this:
foo :: Integer -> Integer -> [Integer]
foo a b = do
let result = []
let Coord x y = boo a b
if x > 0
let result = result ++ [3]
if y > 0
let result = result ++ [5]
if x < a
let result = result ++ [7]
...
Is there a way to make https calls with the Network.Browser package.
I'm not seeing it in the documentation on Hackage.
If there isn't a way to do it with browse is there another way to fetch https pages?
My current test code is
import Network.HTTP
import Network.URI (parseURI)
import Network.HTTP.Proxy
import Data.Maybe (fromJust)
imp...
Hello
What is wrong here, is Lazy Evaluation too?
teste.hs
module Main where
import Control.Parallel(par,pseq)
import Text.Printf
import Control.Exception
import System.CPUTime
import Data.List
import IO
import Data.Char
import Control.DeepSeq
--Calcula o tempo entre o inicio e o fim de rodagem do programa
ti...