I have am using the cwac touchlist sample for drag n drop in touchlist.
I have the touchlist inside the dialog. It works fine.
Until say if I try to drag one of the list item beyond the dialog view might be upperlimit(mLowerBound) or lowerlimt(mUpperBound) the screens starts blinking and all of sudden dialog view gets converted to a black white line. to come out need to press back.
It wont throw any exception but the dialog disapears and we can't to anything.
adding some call stack which I have taken
What could be the possible problem and solution. Please guide me.
mDragPos:4
mHeight:689
touchSlop:24
mUpperBound:136mLowerBound:459
speed:0
y NEW:160
mLowerBound NEW:459
speed:0
y NEW:183
mLowerBound NEW:459
speed:0
y NEW:202
mLowerBound NEW:459
speed:0
y NEW:207
mLowerBound NEW:459
speed:0
y NEW:210
mLowerBound NEW:459
speed:0
y NEW:236
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:278
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:296
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:317
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:336
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:352
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:372
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:379
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:409
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:426
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:451
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:456
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:488
mUpperBound NEW:229
mLowerBound:speed:4
ref:7
speed:0
y NEW:510
mUpperBound NEW:229
mLowerBound:speed:4
ref:7
speed:0
y NEW:532
mUpperBound NEW:229
mLowerBound:speed:4
ref:7
speed:0
y NEW:576
mUpperBound NEW:229
mLowerBound:speed:16
ref:7
speed:0
y NEW:640
mUpperBound NEW:229
mLowerBound:speed:16
ref:7
speed:0
y NEW:372
mUpperBound NEW:229
mLowerBound NEW:459
speed:0
y NEW:383
mUpperBound NEW:229
mLowerBound NEW:459
03-10 10:37:52.280: I/InputReader(2698): dispatchTouch::touch event's action is 1
03-10 10:37:52.280: I/InputDispatcher(2698): Delivering touch to current input target: action: 1, channel '40bd5fe0 com.sample.dndlistview/com.sample.dndlistview.DnDListViewActivity (server)'
Related
I'm new in Haskell and kind of struggling with an issue I'm not even sure I understand so I could use some help to fix it...
I'm trying to create a simple function that, given three digits "a" "b" and "c", would display all combinations where "a" is smaller than "b" and "b" i smaller than "c" while incrementing them. For instance "4", "5" and "6" would give something like "456, 457, 458, 459, 467, 468, 469, 478, 479, 489, 567, 568, 569, 578, 579, 589, 678, 679, 689, 789"
So far my code looks like this :
axx :: Int -> Int -> Int -> Int
axx (x) (y) (z) = if y == 8 && z == 9
then x + 1
else x
ayy :: Int -> Int -> Int -> Int
ayy (x) (y) (z) = let y = if z == 9 && y < 8
then y + 1
else if z == 9 && y == 8
then x + 1
else y
azz :: Int -> Int -> Int -> Int
azz (x) (y) (z) = let z = if z == 9
then y + 1
else z + 1
my_print_comb :: Int -> Int -> Int -> IO ()
my_print_comb (x) (y) (z) = do print (x)
print (y)
print (z)
if (x /= 7 && y /= 8 && z /= 9)
then do
putStr ", "
let x = axx (x y z)
let y = ayy (x y z)
let z = azz (x y z)
my_print_comb(x y z)
else putStr "\n"
But when I try to compile it, I get the "parse error (possibly incorrect indentation or mismatched brackets)" error message regarding the line where my "azz" function starts. I tried looking for similar case on the web but without any luck so far.
Could anyone help me?
You can remove a lot of parentheses: axx (x) (y) (z) -> axx x y z. print (x) should be written print x.
You have to remove let y = and let z = Li-yao said.
Also remove the parentheses
let x = axx (x y z)
let y = ayy (x y z)
let z = azz (x y z)
my_print_comb(x y z)
->
let x = axx x y z
y = ayy x y z
z = azz x y z
my_print_comb x y z
Otherwise x is interpreted as a function applied to y and z.
Using function application manifest what you wrote is axx $ ((x $ y) $ z) when you meant ((axx $ x) $ y) $ z.
infixr 0 $
($) :: (a -> b) -> a -> b
($) = id
In general intead of checking axx x y z = if x == 8 && z == 9 then .. else you use pattern matching axx 8 y 9 = ...
Use undefined :: a to develop iteratively
axx :: Int -> Int -> Int -> Int
axx x 8 9 = x + 1
axx x y z = undefined
Try to separate the IO out of my_print_comb.
Remove let y = and let z = in ayy and azz.
I am studying Haskell and I am learning what is an abstraction, substitution (beta equivalence), application, free and bound variables (alpha equivalence), but I have some doubts resolving these exercises, I don't know if my solutions are correct.
Make the following substitutions
1. (λ x → y x x) [x:= f z]
Sol. (\x -> y x x) =>α (\w -> y w w) =>α (\w -> x w w) =>β (\w -> f z w w)
2. ((λ x → y x x) x) [y:= x]
Sol. ((\x -> y x x)x) =>α (\w -> y w w)[y:= x] = (\w -> x w w)
3. ((λ x → y x) (λ y → y x) y) [x:= f y]
Sol. aproximation, i don't know how to do it: ((\x -> y x)(\y -> y x) y) =>β
(\x -> y x)y x)[x:= f y] =>β y x [x:= f y] = y f y
4. ((λ x → λ y → y x x) y) [y:= f z]
Sol aproximation, ((\x -> (\y -> (y x x))) y) =>β ((\y -> (y x x)) y) =>α ((\y -> (y x x)) f z)
Another doubt that I have is if can I run these expressions on this website? It is a Lambda Calculus Calculator but I do not know how to run these tests.
1. (λ x → y x x) [x:= f z]
Sol. (\x -> y x x) =>α (\w -> y w w) =>α (\w -> x w w) =>β (\w -> f z w w)
No, you can't rename y, it's free in (λ x → y x x). Only bound variables can be (consistently) α-renamed. But only free variables can be substituted, and there's no free x in that lambda term.
2. ((λ x → y x x) x) [y:= x]
Sol. ((\x -> y x x)x) =>α (\w -> y w w)[y:= x] = (\w -> x w w)
Yes, substituting x for y would allow it to be captured by the λ x, so you indeed must α-rename the x in (λ x → y x x) first to some new unique name as you did, but you've dropped the application to the free x for some reason. You can't just omit parts of a term, so it's ((\w -> y w w) x)[y:= x]. Now perform the substitution. Note you're not asked to perform the β-reduction of the resulting term, just the substitution.
I'll leave the other two out. Just follow the rules carefully. It's easy if you rename all bound names to unique names first, even if the renaming is not strictly required, for instance
((λ x → y x) (λ y → y x) y) [x:= f y] -->
((λ w → y w) (λ z → z x) y) [x:= f y]
The "unique" part includes also the free variables used in the substitution terms, that might get captured after being substituted otherwise (i.e. without the renaming being performed first, in the terms in which they are being substituted). That's why we had to rename the bound y in the above term, -- because y appears free in the substitution term. We didn't have to rename the bound x but it made it easier that way.
im having trouble with part C if you could assist me with it and explain how its done as well. thanks you in advance!
(a) As far as I can tell they're just asking that the grammar be rewritten:
<E> -> <E> + <T>
<E> -> <E> - <T>
<E> -> <T>
<T> -> <T> * <F>
<T> -> <T> / <F>
<T> -> <F>
<F> -> (<F>)
<F> -> x
<F> -> y
(b) They want a derivation of (x * y) + x:
( <T> -- <F> -- x
/ /
/ /
/ /
<E> -- <T> -- <F> -- <E> -- <T> -- *
/ \ \
/ \ \
/ \ \
<E> -- + ) <F> -- y
\
\
\
<T> -- <F> -- x
(c) we can define a NPDA which nondeterministically pushes all valid derivations onto the stack then pops off the input in order to accept. The stack would look like this:
stack input remaining
Z (x * y) + x
<E>Z (x * y) + x
<E>+<T>Z (x * y) + x
<T>+<T>Z (x * y) + x
<F>+<T>Z (x * y) + x
(<E>)+<T>Z x * y) + x
<E>)+<T>Z x * y) + x
<T>)+<T>Z x * y) + x
<T>*<F>)+<T>Z x * y) + x
<F>*<F>)+<T>Z x * y) + x
x*<F>)+<T>Z x * y) + x
*<F>)+<T>Z * y) + x
<F>)+<T>Z y) + x
y)+<T>Z y) + x
)+<T>Z ) + x
+<T>Z + x
<T>Z x
<F>Z x
xZ x
Z (empty)
I am trying to dive deep in the folds, considering it seems a very powerful asset to me. However, can you help me with this:
foldr (/) 2 [1,2,3] -- (1/(2/(3/2))), result 0,75 {where 2 is base)
foldr1 (/) [2,2,3] -- (1/(2/(3/2))), result 3.00 {where 2 is base)
I think I am seriously overseeing an essential difference between the folds. Thx
foldr :: (a -> b -> b) -> b -> [a] -> b has as implementation:
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr _ z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
So that means that if we enter foldr f z [x1, x2, x3], then it is evaluated as:
foldr f z [x1, x2, x3]
-> f x1 (foldr f z [x2, x3])
-> f x1 (f x2 (foldr f z [x3]))
-> f x1 (f x2 (f x3 (foldr f z [])))
-> f x1 (f x2 (f x3 z))
So for your example that will evaluate to:
(/) 1 ((/) 2 ((/) 3 2))
= 1 / (2 / (3 / 2))
= 1 / (2 / 1.5)
= 1 / 1.33333...
= 0.75
The foldr1 :: (a -> a -> a) -> [a] -> a function is almost similar, except that in case we see the a 1-element list, we return that element, so the difference is:
foldr1 :: (a -> a -> a) -> [a] -> a
foldr1 _ [x] = x
foldr f (x:xs) = f x (foldr1 f xs)
So that means that for a foldr1 f [x1, x2, x3] we get:
foldr1 f [x1, x2, x3]
-> f x1 (foldr1 f [x2, x3])
-> f x1 (f x2 (foldr1 f [x3]))
-> f x1 (f x2 x3))
So for the sample input, we get:
(/) 2 ((/) 2 3)
= 2 / (2 / 3)
= 2 / 0.6666...
= 3.0
So in case z and xi have the same type, then foldr f z [x1, ..., xn] is equal to foldr1 f [x1, ..., xn, z].
In general
foldr1 op [y1, ..., yn, x]
is essentially the same as
foldr op x [y1, ..., yn]
as long as n >= 1. That is, in your special case
foldr1 (/) [2, 2, 3]
will evaluate to 2/(2/3) = 3.
With the division operator, it's a bit boring, because
foldr1 (/) [y, y, x1, ... , xn]
= y/(y/(foldr1 (/) [x1, ..., xn]))
= foldr1 (/) [x1, ..., xn]
for all n >= 1. So, in your example, it should just return the result of
foldr1 (/) [3]
which is of course 3.0, and it does indeed evaluate to 3.0.
Here is less degenerate example:
foldr1 (/) [2, 3, 5, 7] -- evals to 0.47619047619047616
Here, it gives the same result as 2 / (3 / (5 / 7)), which is in turn
the same as
foldr (/) 7 [2, 3, 5]
I hope it clarifies the order of evaluation a little bit.
(%?) :: Int -> (Int -> Int) -> Int
x %? f = f x
m :: Int -> Int
m v = v %? \z -> z * 2 %? \z -> z + 3 %? \x -> x + z
or simpler
p :: Int -> Int
p v = v %? \z -> z * 2 %? \z -> z + 3
e.g, p 4 = 20
Well, it would help to know what you were expecting it to do. But perhaps it would help to put some explicit parentheses in p:
q :: Int -> Int
q v = v %? (\z -> z * (2 %? (\z -> z + 3)))
Perhaps you were you expecting something more like this:
p2 :: Int -> Int
p2 v = v %? (\z -> (z * 2) %? (\z -> z + 3))
It's probably a good idea to add an infix declaration for any operators you declare, to avoid this sort of confusion. Arithmetic operators have mid-high precedence, but given what the function does you probably want very low precedence anyway.
As an aside--lambdas extend all the way to the right, but I'm guessing that's not what's tripping you up.
%? has too high precedence and is left-associative, so v %? \z -> z * 2 %? \z -> z + 3 is the same as v %? \z -> z * (2 %? \z -> z + 3).
If you want %? to behave like $ use infixr 0 %?, so it has the same precedence and associativity as $.