pattern-matching

Is it recommended to always have exhaustive pattern matches in Haskell, even for “impossible” cases?

微笑、不失礼 提交于 2019-12-22 02:47:08
问题 Is it recommended to always have exhaustive pattern matches in Haskell, even for "impossible" cases? For example, in the following code, I am pattern matching on the "accumulator" of a foldr. I am in complete control of the contents of the accumulator, because I create it (it is not passed to me as input, but rather built within my function). Therefore, I know certain patterns should never match it. If I strive to never get the "Pattern match(es) are non-exhaustive" error, then I would place

Pattern match list with exactly 2 elements in Haskell

廉价感情. 提交于 2019-12-22 02:20:56
问题 I just started learning Haskell and I'm trying to use pattern matching to match a list that has exactly 2 elements. As an exercise, I'm trying to write a function which returns the one but last element from a list. So far I found this: myButLast :: [a] -> a myButLast [] = error "Cannot take one but last from empty list!" myButLast [x] = error "Cannot take one but last from list with only one element!" myButLast [x:y] = x myButLast (x:xs) = myButLast xs Now the line with myButLast [x:y] is

how to find shapes that are slightly elongated oval / rectangle with curved corners / sometimes sector of a circle?

不羁岁月 提交于 2019-12-22 01:21:41
问题 how to recognise a zebra crossing from top view using opencv? in my previous question the problem is to find the curved zebra crossing using opencv. now I thought that the following way would be much easier way to detect it, (i) canny it (ii) find the contours in it (iii) find the black stripes in it, in my case it is slightly oval in shape now my question is how to find that slightly oval shape?? look here for images of the crossing: www.shaastra.org/2013/media/events/70/Tab/422/Modern

Difference between original Boyer–Moore and Boyer–Moore–Horspool Algorithm [closed]

微笑、不失礼 提交于 2019-12-22 01:11:34
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am not able to understand the changes which Horspool made in his algorithm. If you have any link of Boyer–Moore–Horspool algorithm then please do tell me. 回答1: Here are my few observations: BM: Preprocessing complexity: Θ(m + σ) Worst Case : Θ(nm) If pattern exists Θ(n+m) If

Lua XML extract from pattern

一个人想着一个人 提交于 2019-12-21 21:27:56
问题 An application is sending my script an Stream like this one: <?xml version="1.0" encoding="UTF-8"?> <root> <aRootChildNode> <anotherChildNode> <?xml version="1.0"> <TheNodeImLookingFor> ... content ... </TheNodeImLookingFor> </anotherChildNode> </aRootChildNode> </root> I want to extract the TheNodeImLookingFor section. So far, got: data = string.match(Stream, "^.+\<TheNodeImLookingFor\>.+\<\/TheNodeImLookingFor\>.+$") Pattern is recognized in the Stream, but it doesn't extract the node and

F# How to tokenise user input: separating numbers, units, words?

扶醉桌前 提交于 2019-12-21 20:26:40
问题 I am fairly new to F#, but have spent the last few weeks reading reference materials. I wish to process a user-supplied input string, identifying and separating the constituent elements. For example, for this input: XYZ Hotel: 6 nights at 220EUR / night plus 17.5% tax the output should resemble something like a list of tuples: [ ("XYZ", Word); ("Hotel:", Word); ("6", Number); ("nights", Word); ("at", Operator); ("220", Number); ("EUR", CurrencyCode); ("/", Operator); ("night", Word); ("plus",

F# How to tokenise user input: separating numbers, units, words?

会有一股神秘感。 提交于 2019-12-21 20:26:05
问题 I am fairly new to F#, but have spent the last few weeks reading reference materials. I wish to process a user-supplied input string, identifying and separating the constituent elements. For example, for this input: XYZ Hotel: 6 nights at 220EUR / night plus 17.5% tax the output should resemble something like a list of tuples: [ ("XYZ", Word); ("Hotel:", Word); ("6", Number); ("nights", Word); ("at", Operator); ("220", Number); ("EUR", CurrencyCode); ("/", Operator); ("night", Word); ("plus",

Image Classification - Detecting Floor Plans

北城以北 提交于 2019-12-21 19:28:12
问题 I am working on a real estate website and i would like to write a program that can figure out(classify) if an image is a floor plan or a company logo. Since i am writing in php i will prefer a php solution but any c++ or opencv solution will be fine as well. Floor Plan Sample: alt text http://www.rentingtime.com/uploads/listing/l0050/0000050930/68614.jpg alt text http://www.rentingtime.com/uploads/listing/l0031/0000031701/44199.jpg Logo Sample: alt text http://www.rentingtime.com/uploads

Approximate matching of two lists of events (with duration)

丶灬走出姿态 提交于 2019-12-21 18:39:07
问题 I have a black box algorithm that analyses a time series and "detects" certain events in the series. It returns a list of events, each containing a start time and end time. The events do not overlap. I also have a list of the "true" events, again with start time and end time for each event, not overlapping. I want to compare the two lists and match detected and true events that fall within a certain time tolerance (True Positives). The complication is that the algorithm may detect events that

Swift pattern matching with enum and Optional tuple associated values

戏子无情 提交于 2019-12-21 18:32:53
问题 I'm currently using Alamofire and I use an enum to describe the API I used as advised in the readme. The endpoints are represented as follows: public enum API { case GetStops(stopCode:String?) case GetPhysicalStops case GetLinesColors case GetNextDepartures(stopCode:String, departureCode:String?, linesCode:String?, destinationsCode:String?) } The optional parameters are mutually exclusive: public var URLRequest: NSMutableURLRequest { let result:(path:String, parameters:[String:AnyObject]?) =