Search Results

Search found 913 results on 37 pages for 'haskell multicore'.

Page 12/37 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Haskell Add Function Return to List Until Certain Length

    - by kienjakenobi
    I want to write a function which takes a list and constructs a subset of that list of a certain length based on the output of a function. If I were simply interested in the first 50 elements of the sorted list xs, then I would use fst (splitAt 50 (sort xs)). However, the problem is that elements in my list rely on other elements in the same list. If I choose element p, then I MUST also choose elements q and r, even if they are not in the first 50 elements of my list. I am using a function finderFunc which takes an element a from the list xs and returns a list with the element a and all of its required elements. finderFunc works fine. Now, the challenge is to write a function which builds a list whose total length is 50 based on multiple outputs of finderFunc. Here is my attempt at this: finish :: [a] -> [a] -> [a] --This is the base case, which adds nothing to the final list finish [] fs = [] --The function is recursive, so the fs variable is necessary so that finish -- can forward the incomplete list to itself. finish ps fs -- If the final list fs is too small, add elements to it | length fs < 50 && length (fs ++ newrs) <= 50 = fs ++ finish newps newrs -- If the length is met, then add nothing to the list and quit | length fs >= 50 = finish [] fs -- These guard statements are currently lacking, not the main problem | otherwise = finish [] fs where --Sort the candidate list sortedps = sort ps --(finderFunc a) returns a list of type [a] containing a and all the -- elements which are required to go with it. This is the interesting -- bit. rs is also a subset of the candidate list ps. rs = finderFunc (head sortedps) --Remove those elements which are already in the final list, because -- there can be overlap newrs = filter (`notElem` fs) rs --Remove the elements we will add to the list from the new list -- of candidates newps = filter (`notElem` rs) ps I realize that the above if statements will, in some cases, not give me a list of exactly 50 elements. This is not the main problem, right now. The problem is that my function finish does not work at all as I would expect it to. Not only does it produce duplicate elements in the output list, but it sometimes goes far above the total number of elements I want to have in the list. The way this is written, I usually call it with an empty list, such as: finish xs [], so that the list it builds on starts as an empty list.

    Read the article

  • Haskell lists difference

    - by user559354
    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 <interactive>:1:11: Not in scope: "\\\\" Thanks for explanation where I make a mistake.

    Read the article

  • Haskell search an element on a List

    - by user1887556
    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)) 2) Sum the corresponding elements on a list of lists: sumPositions :: [[Int]] -> [Int] sumPositions [] = [] sumPositions (x:xs) = foldl (zipWith (+)) (repeat 0) (x:xs) 3) Sees if the columns in a list are even or not: parityColumn :: [Int] -> [Bool] parityColumn [] = [] parityColumn (x:xs) |head(x:xs) `mod` 2 == 0 = True:parityColumn(xs) |otherwise = False:parityColumn(xs) 4) Does the operation or with two boolean lists: bol :: [Bool] -> [Bool] -> [[Bool]] bol [] _ = [] bol (x:xs) (y:ys)= (map (||x) (y:ys)):(bol xs (y:ys)) 5) Correct List: correct :: [[Int]] -> [[Bool]] correct [] = [] correct (x:xs)=(bol(parityLine (x:xs))(parityColumn(sumPositions(x:xs)))) So what I want is to alter the function correct to [[Int]]-[[Int]] that does this: My Int list(x:xs) With my correct function applied [[0,0,1,1], [[True,True,False,True], [1,0,1,1], [True,True,True,True], [0,1,0,1], [True,True,True,True] [1,1,1,1]] [True,True,True,True]] Now I can see that in the first line third column, False, so I have to correct that number 1 to have a number of 1's even. Result I want that function correct does: [[0,0,0,1], [1,0,1,1], [0,1,0,1], [1,1,1,1]] Thanks.

    Read the article

  • best way to write a-> ..->[a] recursive functions in haskell

    - by Roman A. Taycher
    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 element and returns it as one long list should I keep it like this? should I use func' hidden by a where? should I only use the [a] - b - [a] version and leave the responsibility of passing [variable] to the callee? I might well need to compose these functions and might want to mess around with the order so I'm leaning towards option 3. What do you think?

    Read the article

  • Haskell Input & Passing Values to Functions

    - by Pradeep
    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 for 20 i want to send num it gives me this error ERROR file:.\Project2.hs:126 - Type error in application *** Expression : buyItem currentStockBase art num *** Term : num *** Type : [Char] *** Does not match : Int please help me

    Read the article

  • haskell. words into binary numbers

    - by Katja
    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') && (n <= ord 'Z') = chr(ord 'A'+ n - 1) num2bin :: Integer -> String num2bin n | n >= 0 = concatMap show (reverse ( n2b n)) | otherwise = error "num2bin: negative number" where n2b 0 = [] n2b n = n `mod` 2 : n2b (n `div` 2) he tells me a mistake.I dont undertsand it mistake: Couldn't match expected type `Char' against inferred type `String' In the first argument of `lett2num', namely `x' In the first argument of `num2bin', namely `(lett2num x)' In the expression: num2bin (lett2num x)

    Read the article

  • find if list 1 is a sequence of list 2 in haskell

    - by Isaak Wahb
    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] -> Bool subseq [] [] = True subseq [] ys = True subseq xs [] = False subseq (x:xs) (y:ys) = x == y || subseq xs ( 1 `drop` ys )

    Read the article

  • How do you solve this Haskell problem?

    - by Linda Cohen
    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, how can I do this? THANKS!

    Read the article

  • Haskell type signature with multiple type somethings (predicates?, for example Eq a =>)

    - by Andrew
    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 thing i called a type predicate. My question, though, is how to have multiple of these, so if A is an Eq and B is a Num, I could say either f :: Eq a => a -> b or f :: Num b => a -> b. So, how can I have Eq a => and Num b => at the same time? f :: Eq a => Num b => a -> b, f :: Eq a -> Num b => a -> b, and f :: Eq a, Num b => a -> b all didn't do what I wanted.

    Read the article

  • Simple haskell splitlist

    - by js7354
    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, zs) | otherwise = (l, []) where (ys,zs) = splitlist xs (n - 1) I know I need to change the signature to [a] - ([a],[a]), but where in the code should I put something like length(xs) so that I don't break recursion? Thank you.

    Read the article

  • Haskell: list of elements with class restriction

    - by user1760586
    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: Asdf2 a Perhaps you intended to use -XImpredicativeTypes In the type synonym declaration for `ListOfAsdf2' I have tried a lot of things but I am still not able to create a type with a class restriction as described above. Thanks in advance!!! =) Dak

    Read the article

  • Nested/Sub data types in haskell

    - by Tom Carstens
    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 an error.) At the moment you might do something like: data Major = MinorA | MinorB | MajorB isMinor :: Major -> Bool isMinor MinorA = True isMinor MinorB = True isMinor _ = False It's not terrible or anything, but it doesn't expand nicely (as in if Minor when up to MinorZ this would be terribly clunky). To avoid that problem you can wrap Minor: data Minor = MinorA | MinorB data Major = MajorA Minor | MajorB isMinor :: Major -> Bool isMinor (MajorA _) = True isMinor _ = False But now you have to make sure to wrap your Minors to use them as a Major... again not terrible; just doesn't really express the semantics I'd like very well (i.e. Major can be any Minor or MajorB). The first (legal) example is "Major can be MinorA..." but doesn't have any knowledge of Minor and the second is "Major can be MajorA that takes a Minor..." p.s. No, this isn't really about anything concrete.

    Read the article

  • Haskell: What is the difference between $ (dollar) and $! (dollar exclamation point)

    - by Jelle Fresen
    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 definition as $. When trying some simple statements in a Haskell interpreter (ghci), I couldn't find any difference, nor could I find any reference to the operator in the top listed tutorials when googling for haskell tutorial. So, just out of curiosity, what is the difference, if at all?

    Read the article

  • Why does this Haskell code produce the "infinite type" error?

    - by Charlie Flowers
    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 really appreciate it. Here's the code: intersperse :: a -> [[a]] -> [a] -- intersperse '*' ["foo","bar","baz","quux"] -- should produce the following: -- "foo*bar*baz*quux" -- intersperse -99 [ [1,2,3],[4,5,6],[7,8,9]] -- should produce the following: -- [1,2,3,-99,4,5,6,-99,7,8,9] intersperse _ [] = [] intersperse _ [x] = x intersperse s (x:y:xs) = x:s:y:intersperse s xs And here's the error trying to load it into the interpreter: Prelude :load ./chapter.3.ending.real.world.haskell.exercises.hs [1 of 1] Compiling Main ( chapter.3.ending.real.world.haskell.exercises.hs, interpreted ) chapter.3.ending.real.world.haskell.exercises.hs:147:0: Occurs check: cannot construct the infinite type: a = [a] When generalising the type(s) for `intersperse' Failed, modules loaded: none. Thanks. EDIT: Thanks to the responses, I have corrected the code and I also have a general guideline for dealing with the "infinite type" error in Haskell: Corrected code intersperse _ [] = [] intersperse _ [x] = x intersperse s (x:xs) = x ++ s:intersperse s xs What the problem was: My type signature states that the second parameter to intersperse is a list of lists. Therefore, when I pattern matched against "s (x:y:xs)", x and y became lists. And yet I was treating x and y as elements, not lists. Guideline for dealing with the "infinite type" error: Most of the time, when you get this error, you have forgotten the types of the various variables you're dealing with, and you have attempted to use a variable as if it were some other type than what it is. Look carefully at what type everything is versus how you're using it, and this will usually uncover the problem.

    Read the article

  • How to do i18n and create Windows Installer of Haskell programs?

    - by Aufheben
    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 facing now: I18n of Haskell programs: the method described in Internationalization of Haskell programs did work (partially) if I change the command of executing the program from LOCALE=zh_CN.UTF-8 ./Main to LANG=zh_CN.UTF-8 ./Main (I'm working on Ubuntu 10.10), however, the Chinese output is garbled, and I've no idea why is that. Distribution on Windows: I'm used to work under Linux and build & package my Haskell programs using Cabal, but what is the most natural way to create a one-click Windows Installer from a cabalized Haskell package? Is the package bamse the right way to go? ------ Details for the first problem ------ What I did was: $ hgettext -k __ -o messages.pot Main.hs $ msginit --input=messages.pot --locale=zh_CN.UTF-8 (Edit the zh_CN.po file, adding Chinese translation) $ mkdir -p zh_CN/LC_MESSAGES $ msgfmt --output-file=zh_CN/LC_MESSAGES/hello.mo zh_CN.po $ ghc --make Main.hs $ LANG=zh_CN.UTF-8 ./Main And the output was like: This indicates gettext is actually working, but for some reason the generated zh_CN.mo file is broken (my guess). I'm pretty sure my zh_CN.po file is encoded in UTF-8. Plus, aside from using System.IO.putStrLn, I also tried System.IO.UTF8.putStrLn to output the string, which didn't work either.

    Read the article

  • Multicore Expo

    Event to be held in conjunction with ESC Multi-core processor - Central processing unit - Parallel computing - X86 - Operating system

    Read the article

  • Mastering Multicore

    Researchers find a way to make complex computer simulations run more efficiently on chips with multiple processors Computer simulation - Business - Hardware - Processors - Components

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >