largestDivisible :: (Integral a) => a
largestDivisible = head (filter p [100000,99999..])
where p x = x `mod` 3829 == 0
If p x equals True, head (filter True)? Filtering for True what list?
What values are in p and x?
I want a function that changes (1 to 0) on a list, when number of 1's isn't even. I have done these functions:
1) Sees if the lines in a list are even or not:
parityLine :: [[Int]] -> [Bool]
parityLine [] =[]
parityLine (x:xs)
|sum(x) `mod` 2 == 0 = True:(parityLine(xs))
|otherwise = False:(parityLine(xs))…
So I keep having this small problem where I have something like
func :: a -> b -> [a] -- or basically any a-> ...-> [a] where ... is any types ->
func x y = func' [x] y -- as long as they are used to generate a list of [a] from x
func' :: [a] -> b -> [a]
func = undefined --situation dependant generates a list from each…
im trying to check if a given list is a subsequence of another list:
here are example of lists which gives true:
subseq "" "w"
subseq "w" "w"
subseq "ab" "cab"
subseq "cb" "cab"
subseq "aa" "xaxa"
not (subseq "aa" "xax")
not (subseq "ab" "ba")
i just come to this but in some cases it gives a wrong result
subseq :: Eq a => [a] -> [a]…
I need to convert words into binary numbers.
With a bit help of yours I got this
blCo::String -> Integer
blCo x = num2bin(lett2num x)
blCo (x:xs)
| x:xs = num2bin(lett2num x):blCo xs
num2lett :: Int -> Char
num2lett n
| (n <= ord 'A') && (n <= ord 'Z') = chr(ord 'A'+ n - 1)
| (n <= ord 'a')…
I'm trying make a lists difference. Found directly prelude operator \\\\ that makes lists difference. But errors Not in scope: '\\\\' occurs. Here is my simple from command line interpreter:
Prelude> ([1,2,3] ++ [5,6]) -- works like expected
[1,2,3,4,5,6]
prelude> ([1,2,3] \\\\ [1,2]) -- erros occurs…
putStrLn "Enter the Artist Name"
art <- getLine
putStrLn "Enter the Number of CD's"
num <- getLine
let test= buyItem currentStockBase art num
printListIO (showcurrentList test)
the values i have to pass for buyItem is
buyItem currentStockBase "Akon" 20
but i want to send "Akon" to art and…
I want to define a function replicate to replicate a list of numbers by its value using only list comprehension, for example:
replicate [5,1,3,2,8,1,2]
output: [5,5,5,5,5,1,3,3,3,2,2,8,8,8,8,8,8,8,8,1,2,2]
I know this would be easy to use the 'replicate' built in function but only list comprehension is allow,…
I'm not sure if type predicates is the right term, in fact I've never learned the word for this, so an edit to correct would be helpful - I'm referring to when you give the tipe of function f :: a -> b and you want to say a is a Eq and you say f :: Eq a => a -> b, the name for Eq a => - this is the…
I have the following function which takes a list and returns two sublists split at a given element n. However, I only need to split it in half, with odd length lists having a larger first sublist
splitlist :: [a] -> Int -> ([a],[a])
splitlist [] = ([],[])
splitlist l@(x : xs) n | n > 0 = (x : ys,…
here's my question:
this works perfectly:
type Asdf = [Integer]
type ListOfAsdf = [Asdf]
Now I want to do the same but with the Integral class restriction:
type Asdf2 a = (Integral a) => [a]
type ListOfAsdf2 = (Integral a) => [Asdf2 a]
I got this error:
Illegal polymorphic or qualified type:…
How would I print the multiples of a list of given numbers in a merged, sorted list?
I.e.
take 10 (multiples [4,5])
gives
4,5,8,10,12,15,16,20,24,25
I've got it working for lists of size 2 or 1 but I need a more general solution :)
So what would be nice is if you could do something like the following (not necessarily with this format, just the general idea):
data Minor = MinorA | MinorB
data Major = Minor | MajorB
isMinor :: Major -> Bool
isMinor Minor = True
isMinor _ = False
So isMinor MinorA would report True (instead of…
How to explain Scala's type system to a Haskell expert?
What examples show Scala's advantages?
How to explain Haskell's type system to an advanced Scala practitioner?
What can be done in Haskell that can't be done in Scala?
Can anybody explain the difference in Haskell between the operators ($) and ($!) (dollar sign vs dollar sign exclamation point)?
I haven't seen the use of $! anywhere so far, but while browsing through the Haskell reference on www.zvon.org, I noticed its existence and that it has the exact same…
I am new to Haskell and facing a "cannot construct infinite type" error that I cannot make sense of.
In fact, beyond that, I have not been able to find a good explanation of what this error even means, so if you could go beyond my basic question and explain the "infinite type" error, I'd…
I'm considering using Haskell to develop for a little commercial project. The program must be internationalized (to Simplified Chinese, to be specific), and my customer requests that it should be delivered in a one-click Windows Installer form. So basically these are the two problems I'm…
Designed to deliver ultra-fast IP packet forwarding for telecommunications network infrastructure
Telecommunications network - Telecommunication - Business - Consulting - Solutions Providers
Researchers find a way to make complex computer simulations run more efficiently on chips with multiple processors
Computer simulation - Business - Hardware - Processors - Components
This algorithm makes effcient use of memory resources by limiting the need for garbage collection and takes optimal advantage of multiple cores by employing a "hungry" pull strategy.
Algorithm - Garbage collection - Programming - Memory Management - Languages