int -> [int] convert
Possible Duplicate: Split a number into its digits with Haskell how can i convert integer to integer list Exmple: input: 1234 output:[1,2,3,4] any idee about this problem ? ...
Possible Duplicate: Split a number into its digits with Haskell how can i convert integer to integer list Exmple: input: 1234 output:[1,2,3,4] any idee about this problem ? ...
Every so often when programmers are bitching about null errors/exceptions someone asks what we do without null. I myself have some basic idea of the coolness of option types but I don't have the knowledge or languages skill to best express it. It would be useful if someone could point to or write an GREAT explanation of The undesirab...
Consider the following code I wrote: import Control.Monad increasing :: Integer -> [Integer] increasing n | n == 1 = [1..9] | otherwise = do let ps = increasing (n - 1) let last = liftM2 mod ps [10] let next = liftM2 (*) ps [10] alternateEndings next last whe...
I'm struggling with this code right now. I want to determine whether an integer is divsible by 11. From what I have read, an integer is divisible to 11 when the sum (one time +, one time -) of its digits is divisible by 11. For example: 56518 is divisible by 11, because 8-1+5-6+5 = 11, and 11 is divisible by 11. How can i write this ...
I've heard it's better to read the first edition of "Introduction to Functional Programming" by Bird & Wadler than the second edition. The first edition uses Miranda, and the second edition uses Haskell. Is this a common recommendation? My goal is to get serious about functional programming. Thoroughly knowing the concepts of functio...
I have the following data data A = C1 String | A :@: A deriving(Show) app inp = case inp of a1 :@: a2 -> (C1 "a") :@: (C1 "b") _ -> C1 "c" Why does the case return the input instead of (C1 "a") :@: (C1 "b")? *Test> app (C1 "c") :@: (C1 "d") C1 "c" :@: C1 "d" Works fine if i'll change A :@: A to C2 A A ...
Is there any package to perform Sparse Linear Algebra computations, maybe based on fast and efficient C libraries? I searched on Hackage but I didn't find anything at regard: hmatrix, which uses GSL, BLAS and LAPACK, is great, but doesn't seem to include special algorithms to solve linear systems and eigen-values/vectors problems with sp...
The FC++ library provides an interesting approach to supporting functional programming concepts in C++. A short example from the FAQ: take (5, map (odd, enumFrom(1))) FC++ seems to take a lot of inspiration from Haskell, to the extent of reusing many function names from the Haskell prelude. I've seen a recent article about it, and i...
Can you use Atom for programming C in Haskell? Would that be possible and would that make sense? ...
I've just written this function which simply takes a pair whose second value is in some monad, and "pulls the monad out" to cover the whole pair. unSndM :: Monad m => (a, m c) -> m (a, c) unSndM (x, y) = do y' <- y return (x, y') Is there a nicer and/or shorter or point-free or even standard way to express this? I'...
(Sorry in advance if the question is stupid or obvious -- I don't have a lot of experience with Haskell). Is there a way to express that a type should be an instance of a typeclass in more than one way? This is best illustrated with an example (which is probably somewhat silly): In mathematics, we can say that a semiring is a set that i...
I was asked to write a function that would extract the diagonal of a matrix stored as a list of lists. The first version was to extract the number by indexing the lists, but I soon concluded it isn't a good algorithm for Haskell and wrote another function: getDiagonal :: (Num a) => [[a]] -> [a] getDiagonal [[]] = [] getDiagonal (x...
I want some simple CI for a small dev setup. Two motivations -- a full build takes some time, and an anticipated testsuite will also take some time. I really would rather not dive headfirst into one of the big players that require a java application container or whatever to show fancy graphs with multiple colors and etc. I'd be intereste...
Cabal is giving me mixed messages. When I say: Extensions: DeriveFunctor It says: Warning: Unknown extensions: DeriveFunctor But when I say: GHC-Options: -XDeriveFunctor It says: Warning: Instead of 'ghc-options: -XDeriveFunctor' use 'extensions: DeriveFunctor' For now I'm just going to use the {#- LANGUAGE DeriveFunctor -#} ...
I'm writing a snake game in Haskell. These are some of the things I have: A Coord data type A Line data type A Rect data type A Polygon type class, which allows me to get a Rect as a series of lines ([Line]). An Impassable type class that allows me to get a Line as a series of Coords ([Coord]) so that I can detect collisions between ot...
I just started learning Haskell and I ran into a problem in 2-adic type classes. Here's the important code: data Rectangle = NoRect | Rect (Float,Float) (Float,Float) | Pane deriving (Show) class Collision s1 s2 where collides :: s1 -> s2 -> Bool instance (Collision Rectangle Rectangle) where collides (Rect (aOrX, aOrY...
with the signature diffFolge:: (Integer, Integer) -> [Integer], which applied to the argument pair (m, n), m, n> 0, the episode of the difference values of m and n supplies. The first element of the Result list is m, the last but one element is always is greater than 0 and the last element either 0 or a value strictly less than 0 i writ...
how can i do this integer value is converted to integerlist with three pairs from the and of the integer input : 24889375 output : [375,889,24] ...
with this code digs 0 = [] digs x = x `mod` 1000 : digs (x `div` 1000) for example: 24889375 we take the result [375,889,24] how can i make this one ["375","889","024"] ...
This is a follow up to a previous question: I got an answer I didn't really understand and accepted. So I'll ask again: I still don't understand how this makes sense: type Parse a b = [a] -> [(b,[a])] build :: Parse a b -> ( b -> c ) -> Parse a c build p f inp = [ (f x, rem) | (x, rem) <- p inp ] Now, obviously, p binds to the first ...