No instance for (Num [Integer]) arising from the literal ‘1’
plus1 :: [Integer] > [Integer] > [Integer]
plus1 (x:xs) remain
 (x==0) && (remain==1) = [1] ++ (plus1 xs (remain1) )
 (x==1) && (remain==1) = [0] ++ (plus1 xs remain)
 (x==0) && (remain==0) = [0] ++ (plus1 xs 0)
 (x==1) && (remain==0) = [1] ++ (plus1 xs 0)
 otherwise = []
• No instance for (Num [Integer]) arising from the literal ‘1’
• In the second argument of ‘(==)’, namely ‘1’
In the second argument of ‘(&&)’, namely ‘(remain == 1)’
In the expression: (x == 0) && (remain == 1)
1 answer

your type signature says that
remain
should be:: [Integer]
but you are comparing it with==
to1
with isInteger
. Perhaps your type signature was intended to beplus1 :: [Integer] > Integer > [Integer]
See also questions close to this topic

Generalised newtype deriving on class functions with Functors
I'm developing a class representing key/value mappings, and I've got a function which is basically like
alterF
:class C t where ... alterF :: Functor f => (Maybe (Value t) > f (Maybe (Value t))) > Key t > t > f t
Unfortunately, this breaks
GeneralisedNewtypeDeriving
. In some cases, this is reasonable, asGeneralisedNewtypeDeriving
from what I understand essentially uses Coercible and the functioncoerce
.Coercible
represents types which are representationally equal, i.e. they have the same representation at run time, so we can convert between them for free. For example, given:newtype T a = T a
we have:
Coercible a (T a) Coercible (T a) a
but we don't have (in general):
Coercible (f a) (f (T a)) Coercible (f (T a)) (f a)
For example, GADTs violate this representational equality. But there are lots of values of
f
that do work. For example:Coercible (Maybe a) (Maybe (T a)) Coercible (Maybe (T a)) (Maybe a) Coercible [a] [T a] Coercible [T a] [a] Coercible (Identity a) (Identity (T a)) Coercible (Identity (T a)) (Identity a)
It also occurs to me that this instance could be written:
Functor f => Coercible (f a) (f (T a)) Functor f => Coercible (f (T a)) (f a)
Just using
fmap
. Unlike the usualcoerce
, this wouldn't be free at runtime, but it will work.So I've got a class with 10 functions, 9 of which work fine with
GeneralisedNewtypeDeriving
. There's just this final one which doesn't, which could be resolved mechanically usingfmap
. Do I have to write custom wrapping/unwrapping implementations for all my class functions, or is there a way to either require me to write the implementation for just the problem function or alternatively coax GHC into usingfmap
as part of it'sGeneralisedNewtypeDeriving
? 
Haskell infinite loop in recursive function
i'm trying to implement a function that takes a list of characters and return a list of State. The code compile just fine, everything works great too but i'm getting an infinite loop. The problem is when the character '[' is passed, I want to drop the head of stackStates. I don't quite get why i'm getting this infinite loop.
I already try :
stackStates = drop 1 stackStates
but I've got the same infinite loop.
any help would be very appreciated.
data State = State { num :: Int, octave :: Int, duration :: Double, volume :: Double } deriving (Eq, Show) loopOnList :: [Char] > State > [State] loopOnList [] _ = [] loopOnList (x:xs) stateStart  x == '!' = stateStart : loopOnList xs stateStart  x == '[' = do stateStart : stackStates loopOnList xs stateStart  x == ']' = do let etatPile = pileSansElement stateStart stackEtats tempStack = drop 1 stackStates stackStates = tempStack loopOnList xs etatPile  otherwise = loopOnList xs stateCurrent where stateCurrent = (selectOption x stateStart) stackStates = []

Define bind without join for the list monad in Haskell
I understand the definition of
>>=
in term ofjoin
xs >>= f = join (fmap f xs)
which also tells us that
fmap + join
yields>>=
I was wondering if for the
List
monad it's possible to define withoutjoin
, as we do for example forMaybe
:>>= m f = case m of Nothing > Nothing Just x > f x

Detect archive type
I have an archive without extension, how i can detect the file format?
Begin of file (text):
ef cd ab 19 14 00 05 00 08 00 1b 8c 2f 34 63 e3 f1 35 68 00 00 00 8c 00 00 00 09 00 00 00 49 4e 44 45 58 2e 53 59 53 90 77 a2 38 fc 2f 53 09 a9 df 40 2d 0f d5 8f 89 2e 2f a1 eb e2 2e a1 9a 02 39 5d ad 4c b1 cc ca e4 e4 ab 83 a6 ef 1d ab 1f 66 b5 fd 2b f5 81 aa 9d b4 19 34 52 f3 24 58 15 45 4a 38 4a c0 84 19 22 6b ad ef 28 e3 89 36 e7 aa e2 aa 64 dd 19 4b 5d 8b 38 7a 15 14 77 a2 7e f4 e0 be ba f9 bd a3 e5 4e 54 12 c6 47 d6 cc ef cd ab 19 14 00 05 00 08 00 f4 80 51 4c a4 35 50 85 b4 00 00 00 d9 00 00 00 08 00 00 00 49 4e 46 4f 2e 53 59 53 52 b4 68 91 65 88 05 26 da 72 0a 5f ce a3 8e 2a cc 6d a2 8f 9e 36 d6 fa f8 84 7d 43 0d 95 1b 7c 15 ee 3f ba 43 13 41 7f de 47 f1 3c a6 4f 45 e5 cc 0d 32 1b 7c 62 c2 8d d6 f1 f7 d8 f2 88 14 62 a1 ac 6e 96 e5 85 db bd 82 40 e4 83 a9 88 a8 90 26 89 fd aa b1 85 71 10 30 2a 2d c2 ce e1 3c 13 4b 3c 13 13 60 e1 76 87 df c4 9b ef 4f 2a c2 bd 74 14 de 42 d8 f2 77 a1 60 31 fb 72 ec 88 1e 41 72 3c de 2a f0 ac de a3 31 fb ee 11 30 1b f7 fb d8 3b 74 26 b2 56 46 03 a2 b3 7e 87 00 1b 6b 84 c3 ea ae be f0 0c 9c 2f 11 44 74 75 c9 2d 92 c1 ac 24 6a 31 ef cd ab 19 14 00 05 00 08 00 8d a9 47 32 08 85 79 7f f0 00 00 00 22 01 00 00 0c 00 00 00 51 4d 57 57 49 4e 4a 47 2e

Recursive DataType in Scala
Hi I was wondering if someone could explain this signature I found in the Spark codebase. It looks like a recursive datatype, it's used to build the query plan so it kind of makes sense. Does anyone have anymore detailed knowledge of this?
abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product

Recursion in conditional definition in Haskell gives error ( Occurs check: cannot construct the infinite type:)
I want to define a function conditional and using recursion in Haskell (ghci 7.x) like:
partitions n k m = gfunct n k m where gfunct n k m  n == 0 && k == 0 = 1  n < m  k == 0 = 0  otherwise = gfunct (nm,k1,m+1) + gfunct (n,k,m+1)
I get an error:
fib.hs:20:35: Occurs check: cannot construct the infinite type: a1 ~ t6 > (t5, t6, t7) > a1 Relevant bindings include m :: (t5, t6, t7) (bound at fib.hs:17:23) k :: t6 (bound at fib.hs:17:21) n :: (t5, t6, t7) (bound at fib.hs:17:19) gfunct :: (t5, t6, t7) > t6 > (t5, t6, t7) > a1 (bound at fib.hs:17:12) In the first argument of ‘(+)’, namely ‘gfunct (n  m, k  1, m + 1)’ In the expression: gfunct (n  m, k  1, m + 1) + gfunct (n, k, m + 1)
What am I doing wrong?

I want to create hyper links on the page programmatically when there is http or https in the text
So far my output on the page looks like this:
11 : Blah blah blah https://tsomelink : 12 : Blah blah blah
How can I change the lines that have http or https to hyperlinks for that specific text?
Right now my code that displays the text looks like this:
showResults = () => { return( <div> <span> {this.state.queryData.map((i, index) => <div className = "results"> <p key = {i} className = "twitterresults"> {index+1 + " : " + i + " : "}</p> <p className= "twittername" key = {index}> {this.state.name[index]} </p> </div>)} </span> <br /> <span> The Count is: {this.state.count} </span> </div> ) }
I'm wondering what the best way would be to add those hyperlinks with JS and React.

moving from for() to map()  can't get my head around it
Wondering if someone can help  I'm wanting to use
Array.map
andArray.filter
but i'm so stuck in myfor
loop thinking that despite reading tutorials etc i can't seem to get my head around this.In this code, I have an
Array
of objects, I want to: compare each item in the array with the other items, and ensure that
obj[i] != obj[i]
 perform operations on current item: check if
item.target
isnull
, comparedistance
betweenitem
anditem+1
, and ifitem
&item+1
distance
is smaller thanitem
&item.target
then i want to replaceitem.target
withitem
.
code:
for (var i = 0; i < 111; i++) { var itm = {x:Math.random()*w, y:Math.random()*h, tgt:null}; dotArr.push(itm); } function findTarget(itemA, itemB){ var x1 = itemA.x; var y1 = itemA.y; var x2 = itemB.x; var y2 = itemB.y; var distance = Math.sqrt( (x2=x1)*x2 + (y2=y1)*y2 ); return distance; } for (var i = 0; i < dotArr.length; i++) { let itm = dotArr[i]; for (var j = 0; j < dotArr.length; j++) { if(itm != dotArr[j]){ let itm2 = this.dotArr[j]; if(itm.tgt==null){ itm.tgt = itm2; }else{ let newDist = findTarget(itm, itm2); let curDist = findTarget(itm, itm.tgt); if(newDist<curDist){ itm.tgt = itm2; } } } } }
All the 'multiply each value by 2' examples in the tutorials i read make sense but can't extrapolate that into an approach that i use all the time.
Expected results: i have a bunch of particles, they are looping through a requestAnimationFrame() loop, checking the distance each loop. Each particle finds the closest particle and sets it to 'tgt' (and then moves toward it in other code), but it updates each loop.
 compare each item in the array with the other items, and ensure that

translating compose functions from javascript to python, the functional way
I'm trying to translate my Javascript compose functions into Python but I'm having trouble with the last one. How can I generalize an unknown number of functions?
After reading this, I would like to avoid the
reduce()
method.javascript:
/* compose functions */ const comp1 = (fn2, fn1) => arr => fn2(fn1(arr)) // 2 functions, one array const comp2 = (fn2, fn1) => (...arrs) => fn2(fn1(...arrs)) // 2 functions, multiple arrays const comp3 = (...fns) => (...arrs) => fns.reduceRight((v,f) => f(v), ...arrs) // multiple functions, multiple arrays
python:
/* compose functions */ comp1 = lambda fn2,fn1: lambda arr: fn2(fn1(arr)) # 2 functions, 1 array comp2 = lambda fn2,fn1: lambda *arrs: fn2(fn1(*arrs)) # 2 functions, multiple arrays comp3 = lambda *fns: lambda *arrs: ????
all improvements are appreciated...