I have been trying to explain the difference between switch statements and pattern matching(F#) to a couple of people but I haven't really been able to explain it well..most of the time they just look at me and say "so why don't you just use if..then..else".
How would you explain it to them?
EDIT! Thanks everyone for the great answers...
I want to do some pattern matching on lists in Python. For example, in Haskell, I can do something like the following:
fun (head : rest) = ...
So when I pass in a list, head will be the first element, and rest will be the trailing elements.
Likewise, in Python, I can automatically unpack tuples:
(var1, var2) = func_that_returns_a_tu...
Language: C#
Hello, I'm writing an application that uses renaming rules to rename a list of files based on information given by the user. The files may be inconsistently named to begin with, or the filenames may be consistent. The user selects a list of files, and inputs information about the files (for MP3s, they would be Artist, Tit...
Hello, I'm currently working on a small project with Ocaml; a simple mathematical expression simplifier. I'm supposed to find certain patterns inside an expression, and simplify them so the number of parenthesis inside the expression decreases. So far I've been able to implement most rules except two, for which I've decided to create a r...
var pattern = /^0+$/;
My guess is this:
"Take a look at both the beginning and the end of the string, and if there's a pattern of one or more zeros at the beginning and the end, then return that pattern."
I'm sure that's wrong, though, because when I run the expression with this string:
var string = "0000009000000";
It comes up nu...
Hi,
Anyone know a good and effective way to search/match for a byte pattern in an byte[] array and then return the positions.
e.g.
byte[] pattern = new byte[] {12,3,5,76,8,0,6,125};
byte[] toBeSearched = new byte[] {23,36,43,76,125,56,34,234,12,3,5,76,8,0,6,125,234,56,211,122,22,4,7,89,76,64,12,3,5,76,8,0,6,125}
...
We have an internal .NET case management application that automatically creates a new case from an email. I want to be able to identify other emails that are related to the original email so we can prevent duplicate cases from being created.
I have observed that many, but not all, emails have a thread-index header that looks useful.
...
I need a RegExp which matches a word or multiple words in quotes.
[\w]* matches a word
"[\w\W&&[^"]]*" matches multiple words in quotes.
(btw, not sure why \w\W works, but not a simple . (which should match all characters)
So how do i combine these two regexp?
...
Hi,
I'm trying to find a way to make a list of everything between <a> and </a> tags. So I have a list of links and I want to get the names of the links (not where the links go, but what they're called on the page). Would be really helpful to me.
Currently I have this:
$lines = preg_split("/\r?\n|\r/", $content); // content is the giv...
What are the best algorithms for recognizing structured data on an HTML page?
For example Google will recognize the address of home/company in an email, and offers a map to this address.
...
What I want to do is take a certain stock pattern (defined as a series of x and y coordinates) and compare it against historical stock prices. If I find anything in the historical prices similar to that pattern I defined, I would like to return it as a match.
I'm not sure how to determine how similar two curved lines are. I did some r...
I have a file containing several lines similar to:
Name: Peter
Address: St. Serrano número 12, España
Country: Spain
And I need to extract the address using a regular expression, taking into account that it can contain dots, special characters (ñ, ç), áéíóú...
The current code works, but it looks quite ugly:.
Pattern p = Pattern.com...
I have some old software (in a language that's not dead but is dead to me ;-)) that implements a basic pattern-matching and -rewriting system for source code. I am considering resurrecting this code, translating it into a modern language, and open-sourcing the project as a refactoring power-tool. Before I go much further, I want to know ...
I want to strengthen a pattern to match only numbers which pass an additional validation function.
let (|IsValid|_|) n = ...
let (|Nil|One|Two|) (l : int list) =
match l with
| a :: b :: t -> Two(a + b)
| a :: t -> One(a)
| _ -> Nil
The 'One' case is easy:
| IsValid(a) :: t -> One(a)
The 'Two' c...
I'm just curious about the efficiency of pattern matching in Haskell. What is a simple case of where pattern matching would be better than nested if/case statements and then the converse?
Thanks for your help.
...
I want to do the following with regular expressions but not sure how to do it. I want it to match "one two" when one two is the beginning of the line unless the string contains "three" anywhere after "one two". Note the " marks are just to represent string literals I don't need to match on them.
...
Update this question was previously titled as "Give me the name of a simple algorithm for signal(sound) pattern detection"
My objective is to detect the presence of a given pattern in a noisy signal. I want to detect the presence of a species of insect recording the sounds with a microphone. I have previously recorded the sound of the ...
I've just noticed F# allows me to use let bindings with literals and other patterns as follows:
let fib 0 = 1
let exists item [] = false
let car (hd :: tl) = hd
let cdr (hd :: tl) = tl
F# correctly interprets these functions as a kind of pattern matching, because gives me the following warnings:
Warning 1 Incomplete pattern matc...
(This is no homework and no work issue. It's just my personal interest/occupation and completly fictional. But I am interested in a good algorithm or data structure.)
Let's assume, that I would run a dating site. And my special feature would be that the singles were matched by movie taste. (Why not?)
In that case I would need a way to ...
Obviously, you can use | (pipe?), to represent OR, but can you match 'and' as well?
Specifically, I'm wanting to match paragraphs of text that contain ALL of a certain phrase, but in no particular order.
...