pattern-matching

How to case match a type variable enclosed in a generic type?

微笑、不失礼 提交于 2019-12-13 01:04:42
问题 I'm writing a Scala subroutine to construct a TypeTag[Map[_<: A, _<: B]] from 2 typetags: tag1: TypeTag[Iterable[_<: A]] tag2: TypeTag[Iterable[_<: B]] The upperbound is necessary because both A and B are declared as covariant, yet TypeTag[T] is invariant. I'm trying to use case match to get implicit type variables of A and B, but found that type pattern match in Scala is relatively week. Namely, the folloing code fails to be compiled: (tag1, tag2) match { case (tt1: TypeTag[Iterable[t1]],

Rotate function in Haskell

荒凉一梦 提交于 2019-12-12 21:33:28
问题 I want to write a function in Haskell that rotates the list given as the second argument by the number of positions indicated by the first argument. Using pattern matching, implement a recursive function I have written the following function: rotate :: Int -> [a] -> [a] rotate 0 [y]= [y] rotate x [y]= rotate((x-1) [tail [y] ++ head [y]]) but this function always produces a error. Is there any way to solve it? The function should do the following when it runs: rotate 1 "abcdef" "bcdefa" 回答1:

Match combinations of row values between 2 different data frames

那年仲夏 提交于 2019-12-12 19:22:34
问题 I have a data.frame with 16 different combinations of 4 different cell markers combinations_df FITC Cy3 TX_RED Cy5 a 0 0 0 0 b 1 0 0 0 c 0 1 0 0 d 1 1 0 0 e 0 0 1 0 f 1 0 1 0 g 0 1 1 0 h 1 1 1 0 i 0 0 0 1 j 1 0 0 1 k 0 1 0 1 l 1 1 0 1 m 0 0 1 1 n 1 0 1 1 o 0 1 1 1 p 1 1 1 1 I have my "main" data.frame with 10 columns and thousands of rows. > main_df a b FITC d Cy3 f TX_RED h Cy5 j 1 0 1 1 1 1 0 1 1 1 1 2 0 1 0 1 1 0 1 0 1 1 3 1 1 0 0 0 1 1 0 0 0 4 0 1 1 1 1 0 1 1 1 1 5 0 0 0 0 0 0 0 0 0 0 ...

Regular Expression Match to Extract Command

痴心易碎 提交于 2019-12-12 18:39:32
问题 String: Z123xy;Z123od33;Z123od343;Z251od541; Regex: Z.*?od.*?; Required Output: [Z123od33; Z123od343; Z251od541;] But Current Output : [Z123xy;Z123od33; Z123od343; Z251od541;] I know why its happening that way but don't know how to solve this. Any one could help please 回答1: You could go for Z[^;]*?od[^;]*?; # require a Z # anything not a ; lazily # od # anything not a ; lazily again # followed by a ; See a demo on regex101.com or split on the ; and analyze the parts later separately. 来源:

How does extglob work with shell parameter expansion?

放肆的年华 提交于 2019-12-12 17:26:20
问题 I thought I understood the use of the optional ?(pattern-list) in bash (when extglob shell option is on) and by default in ksh. For example in bash : $ shopt -s extglob $ V=35xAB $ echo "${V#?(35|88)x}" "${V#35}" AB xAB But when the matching prefix pattern is just one ?() or one *() , which introduce what I call optional patterns , the 35 is not omitted unless ## is used: $ echo "${V#?(35|88)}" "${V#*(35|88)}" # Why 35 is not left out? 35xA 35xA $ echo "${V##?(35|88)}" "${V##*(35|88)}" # Why

? LIKE (column || '%')

余生颓废 提交于 2019-12-12 17:15:25
问题 Can I have a condition of something like this: SELECT * FROM table WHERE ? LIKE (column || '%') Where the ? is a string parameter value. For example, these parameter value ? should return true when column is equal to /admin/products /admin/products/1 /admin/products/new /admin/products/1/edit Is this possible? Update: Added test case. Basically, the where clause would render like this: 1. ? LIKE (column || '%') 2. '/admin/products/1' like ('/admin/products' || %) 3. '/admin/products/1' like (

Is it possible, with simple F# pattern matching transformations, to ignore unmatched values without a warning?

蹲街弑〆低调 提交于 2019-12-12 16:16:38
问题 So, I previously asked this question: Can someone help me compare using F# over C# in this specific example (IP Address expressions)? I was looking at the posted code and I was wondering if this code could be written without it producing a warning: let [|a;b;c;d|] = s.Split [|'.'|] IP(parseOrParts a, parseOrParts b, parseOrParts c, parseOrParts d) Is it possible to do something for the match _ pattern ot ignore? Without adding in something like Active Patterns? i want to keep the code as

Agda: Why am I unable to pattern match on refl?

拟墨画扇 提交于 2019-12-12 13:31:53
问题 I'm trying to prove things about divisibility on integers. First I tried to prove that divisibility is reflective. ∣-refl : ∀{n} → n ∣ n Because I defined divisibility based on subtraction... data _∣_ : ℤ → ℤ → Set where 0∣d : ∀{d} → zero ∣ d n-d∣d : ∀{n d} → (n - d) ∣ d → n ∣ d ...it seems easy if I use the fact that n-n=0 : ∣-refl {n} with n-n≡0 n ... | refl = n-d∣d 0∣d But Agda rejects to pattern match on refl. Even if there is no possible other normal form of n-n=0 n . I've proven this

Haskell: pattern matching on Num types

ぐ巨炮叔叔 提交于 2019-12-12 13:13:56
问题 Why can't Haskell perform pattern matching on Num types, without us specifying Eq as a type class? For instance: h :: Num a => a -> a h 0 = -1 h x = x + 1 When compiling this function, ghci complains: * Could not deduce (Eq a) arising from the literal `0' from the context: Num a bound by the type signature for: h :: forall a. Num a => a -> a at functions.hs:9:1-20 Possible fix: add (Eq a) to the context of the type signature for: h :: forall a. Num a => a -> a * In the pattern: 0 In an

Python finding patterns within large group of numbers? [duplicate]

不想你离开。 提交于 2019-12-12 12:11:59
问题 This question already has answers here : Finding a repeating sequence at the end of a sequence of numbers (5 answers) Closed 6 years ago . I'm working with a list of lists that have the periods of continued fractions for non-perfect square roots in each of them. What I'm trying to do with them is to check the size of the largest repeating pattern in each list. Some of the lists for example: [ [1,1,1,1,1,1....], [4,1,4,1,4,1....], [1,2,10,1,2,10....], [1,1,1,1,1,4,1,4,1,20,9,8,1,1,1,1,1,4,1,4