Author Archives: Robins

Haskell learning — Grammar


if-then-else
Haskell is an expression-oriented language, so all statements must be able to give a concrete value. For example, we like the iF-else structure:

Prelude> if True then 1

<interactive>:24:15:
    parse error (possibly incorrect indentation or mismatched brackets)

Can’t compile?In fact, if a then 1 can be compiled, the expression will not be able to give a specific value when a is set to False — quite different from imperative languages. Imperative languages are sequences of statements, and it makes little sense to care about the return value of iF-else. Haskel, on the other hand, says that all expressions must give a value, so —

We have to fill in the else:

Prelude> if True then 1 else "foo"

<interactive>:2:14:
    No instance for (Num [Char])
        arising from the literal `1'
    Possible fix: add an instance declaration for (Num [Char])
    In the expression: 1
    In the expression: if True then 1 else "foo"
    In an equation for `it': it = if True then 1 else "foo"

Still doesn’t compile?

The mistake is obvious. As a pure function language, as a language for static type analysis, a pure expression with different types of return values on different inputs, this behavior is simply intolerable. So, change “foo” to 2, and you’ll pass:

Prelude> if True then 1 else 2
1

Here’s a more complex example (don’t forget that the function definition is best placed in a hs file) :

myDrop n xs = if n <= 0 || null xs
              then xs
              else myDrop (n - 1) (tail xs)

This is a function that simulates a drop. Well, it’s not that complicated. It’s just a recurrence or something.

Also note that NULL is a function that accepts a list and returns a Bool to indicate whether the list is empty:

Prelude> :info null
null :: [a] -> Bool 	-- Defined in `GHC.List'

You can also see some of the ways Haskell’s types derive from this example. Why does Haskell know that XS is a list?How does Haskell know the return value of myDrop?How does Haskell infer type contradiction?This isn’t the point of this article, but it’s interesting enough to write about.

First, you can see that null’s input must be a [a], and tail’s must be a [A], so Haskell automatically determines that XS is an [A] type.
Then, you can see from the return of then in if-then-else that one of myDrop’s returns is xs, so myDrop’s return type is at least [a] — xs is of type [a], but sometimes it’s more specific to [Num], Char, etc., so at least.
Finally, according to the else statement, it is now assumed that the return type of myDrop is [a], and myDrop (n-1) (tail XS) conforms to the input of myDrop as a legal statement, so it returns type [a] without other conditions.
The above three steps are a very simple process, but the operation is a little more complicated than this because Haskell also needs to consider various subtyping problems, but the principle is not really complicated. For those interested, see Types+and+Programming+Languages. RWH and TPL match to see the effect of the group!
Also note that it’s actually fine to write this function on the same line, but it’s hard to read:

myDropX n xs = if n <= 0 || null xs then xs else myDropX (n - 1) (tail xs)

Although Haskell isn’t as strict about indentation as Python, don’t omit indentation — it perpetuates an existing definition rather than creating a new one.

Pattern matching

Inertia is evaluated

Many languages provide short-circuit evaluation. So let’s say exp1 &amp in C; & Exp2 expression, exp2 will not be evaluated after exp1 has been evaluated as false. This is a minimization computing strategy for logical operators.

A similar example can easily be found in Haskell

True || (length[1..] > 0)

Remember the infinite list [1..] ?View directly in GHCI [1..] If you do not force the ghci process to end, you will be left with an infinite refresh. But this expression can terminate normally because True on the left short-circuits the calculation on the right.

Unlike short-circuit evaluation, lazy evaluation takes this minimization to the extreme

An expression is evaluated not immediately after it is bound to a variable, but when the value is accessed, i.e., the statement x:=expression; (give the result of an expression assignment to a variable) obvious call this expression was calculated and the results to x, but no matter what is actually in the x first, until later by the reference to the x in the expression and the demand for its value, and the expression evaluation can also be delay, finally in order to generate a symbol for the outside world to see and computing this rapidly growing dependence on the tree. (from
wiki)

Consider the following code:

head [1..]

If it were Python, this would be a big hassle — the arguments passed to the head would have to be specified so that they would hang. However, with the lazy evaluation strategy, it can give the result 1 normally.

Or consider the scarier expression:

head (tail [1..])

Haskell gives the correct result 2, but don’t forget (tail [1..] The result of)
An infinite list too! Therefore, a policy of lazy evaluation does not require that the input be specified, nor does it require that the output be specified. It only requires that the
The statute does not begin until it has to be made.

This lazy evaluation strategy makes it possible for users to construct infinite lists. Let’s say a Fibonacci sequence —

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

The list is not evaluated at definition time, otherwise it is theoretically endless unless you run out of memory.
What good is an infinite list like
?

Imagine a C programmer one day writing a function that sums the first n terms of Fibonacci, the next day writing a function that sums the first n even terms, and the third day returning the NTH term of Fibonacci. Wouldn’t he be crazy to write Fibonacci over and over again – although the function doesn’t change much each time.

Once the infinite list fiBS is constructed, he doesn’t need to worry about Fibonacci itself, the only thing he needs to write is the function that operates on the list. Even if he had to replace all of Fibonacci with a difference series the next time, he wouldn’t have changed much.

It’s been said that object-oriented languages are the most modular of all, but at this point object-oriented is too Young too Simple.

Haskell’s lazy evaluation isn’t as glamorous as it sounds. Some say it’s good, some say it’s bad. For example, the so-called “lazy accumulation” may be a serious problem.

In Haskell’s implementation of lazy evaluation, it introduces a concept called Thunk (customically, some might call it bottom), which means that an object has not yet been evaluated — which incurs three costs:

First, every time an object is used, it needs to be checked to see if the object has been evaluated, which is not negligible in the case of large amounts of data, and cannot be optimized by the compiler because it is a runtime check.

Second, there is the so-called “inert accumulation”. This may not sound like much — all the computation is necessary, after all — but it makes the performance of the program hard to analyze, which can have a detrimental effect on the testing of large projects.

Finally, all of Haskell’s Thunk must undergo “side effects” to be updated. This means that all of this Thunk must be stored in memory and not in registers. Memory utilization aside, this audacity to ignore the differences in the speed of a computer’s storage hierarchy is Owen’s utopian socialism.

Wang Yin’s blog post reads as follows:

Haskell is actually a very problematic language. Their designers try to make a virtue out of a weakness. When you gently criticize its design, its fans always say in a high voice that there is so much truth in it that you don’t understand. Ironically, this is also the attitude they take when faced with an expert like me who is superior to its designer. Maybe it’s just the way people are: the more you respect them, the more tactful they are, the more they think you don’t understand and continue to try to fool you.

In my view, Haskell is probably just a testing ground for typing systems, rank-n Polymorphism, efficiency and so on-except that the idea that languages must be complete gives Haskell too much to waste. We give pure reason legs, but pull off its wings, may be more easily run on the ground, jump, but can no longer fly in the sky.

In fact, there are more reduce strategies: Full beta-reduction, Normal Order, call by Name, and Call by Value are the four most commonly discussed strategies, while the last one is the most widely used in programming language design. Haskell USES a strategy similar to call by Name, but because thunk exists, each particular value is specified only once — what Wadsworth calls call by need.

iOS Frequent Error Domains = NSURLErrorDomain Code = -1005 “Network Connection Lost.”

Reference links: https://stackoverflow.com/questions/25372318/error-domain-nsurlerrordomain-code-1005-the-network-connection-was-lost
Java code:

response.setHeader("Connection", "Keep-Alive");
response.setHeader("Keep-Alive", "timeout=60000");

If you are satisfied, please send the amount of money to the director of the blog. If you are interested, add the blogger WeChat when transferring money to WeChat. Please leave a comment below and feel free to discuss it with the bloggers.

Informatica error: Invalid connection license key for CMN_1022 [database [Microsoft SQL Server] solution

1. No problems caused by Lincense
Problem: The connection license key for CMN_1022 [database [Microsoft SQL Server] is invalid
Solution: Check your license on the console (click license to view permissions). Switch to ODBC connections.
 
2. Odbc connection to SQLServer.
In the system ODBC, establish a connection, for example: odBC_ORa_HR, test to see if it can connect to the remote Oracle Server. When you set up ODBC in the Workflow Manager, that ConnectString puts the name odBC_ora_hr. Odbc_ora_hr should be ok if it’s accessible from your system’S ODBC

R language error messages and related solutions

Original: Huang Xiaoxian
Error: object of type ‘closure’ is not subsettable
object is not subsettable, see if the object is empty, sometimes the file path or name is wrong, data is not imported successfully
Remove duplicates before running TSNE
there can be duplicate data lines. There is a parameter in the package Rtsne, check_duplicates = FALSE
Error in colMeans(x, na.rm = TRUE) : ‘x’ must be numeric
. The data imported by that numeric contains columns that are not numeric, which may be factors.
can be checked using sapply (x, class)
Error: (list) object cannot be coerced into type ‘double’
. If using as.matrix cannot convert columns whose type is factor to numeric,
can use lapply(x,as.numeric) to convert the factor type to numeric
Error in install. Packages: cannot remove prior installation of package ‘digest’
can directly delete the corresponding package in the folder stored in R package
Error in df$type: $ operator is invalid for atomic vectors
The $method element

Error in file(file, ifelse(append, “a”, “w”)) :

NS_ERROR_DOM_BAD_URI: Access to restricted URI denied

If our js file contains Ajax code, and references the HTML file of this js file, open the test directly locally, this error will appear:
as shown below:
util. Js file

function ajax(url,options,type){
    var oAjax=null;
    var type=type || "GET";
    //alert(type);
    if(window.XMLHttpRequest){
        oAjax=new XMLHttpRequest();

    }
    else{
        oAjax=new ActiveXObject('Microsoft.XMLHTTP');
    }

    oAjax.onreadystatechange=function(){
        if (oAjax.readyState==4) {
            if (oAjax.status==200) {
                options.onsuccess(oAjax.responseText);
            } 
            else{
                options.onfail();
            };
        };
    }

    url=url+"?name="+options.data.name+"&password="+options.data.password+"&t="+Math.random();
    oAjax.open(type,url,true);
    oAjax.send();
}

Assuming that there are other functions in the util.js file that we need, when we introduce util.js into the HTML file, the local browser opens the test with an error

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>task0002</title>
    <script type='text/javascript' src='js/util.js'></script>
</head>
<body>
   <textarea name="hobby" id="hobby" cols="30" rows="10"></textarea><br/>
    <input type="button" id='btn' value='filtration'>
    <script>
        var oTxt=document.getElementById('hobby');
        var btn=document.getElementById('btn');
         var p=document.createElement('p');
         document.body.appendChild(p);
        btn.onclick=function(){
            var hobbys=oTxt.value;
            var ary=hobbys.split(/[,、;\n\s,\u3000]/);
            ary=uniqArray(ary);
            p.innerHTML="";
            p.innerHTML="hobby:"+ary.join("<br/>");
        }
    </script>
</body>
</html>

The reason: When local browsing opens the page, a cross-domain problem occurs, so the message is that you don’t have permission
Solution:
1. Put the ajax code part in the HTML file, there will be no problem
2. By placing the project folders on the server, they will be in one domain by default and cross-domain problems will not occur

Android Studio Error: Invoke-customs are only supported starting with Android O (–min-api 26)

Follow Android 007 and get the full set of Android development learning materials for free
Android Studio compiler error reporting:
Error: Invoke-customs are only supported starting with Android O (–min-api 26)
Solutions:
Add under Android node in build.gradle file:

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }


Summary of the Android development tutorial series
A preliminary study on the android
Install development tools
Create your first Android project
Developing language learning
Kotlin language foundation
UI control learning series
UI control _TextView
UI control _EditText
UI control _Button
UI control _ImageView
UI control _RadioButton
UI control _CheckBox
UI control _ProgressBar

MYSQL ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

This may be because MySQL has set foreign Key association in InnoDB, which makes it impossible to update or delete data. You can avoid this situation by setting the FOREIGN_KEY_CHECKS variable.
SET FOREIGN_KEY_CHECKS = 0;
SET
SET FOREIGN_KEY_CHECKS = 1;

SET FOREIGN_KEY_CHECKS = 0;
SET
SET FOREIGN_KEY_CHECKS = 1;
ERROR 1452 (23000): Cannot add or update a Child row: a foreign key constraint fails…… (foreign key restrictions cannot be inserted)
can also use (SET FOREIGN_KEY_CHECKS = 0; ) insert

c++ terminate called after throwing an instance of ‘std::system_error‘ what(): Unknown error -1

During thread programming, the compiler broadcasts
Terminate called after throwing an instance of ‘STD ::system_error’
you are able to terminate called br> what(): Unknown error-1
Aborted (core dumped)
and add the -pthread option. G++ -std=c++11 -pthread thread_demo.cpp-o demo.
When Clion compiles, this error is reported. You need to modify the compile option at cmakelists. TXT.

CentOS 7 installation error: Cannot find a valid baseurl for repo: base/7/x86_6

If centos in Docker reports an error, restart Docker service, Service Docker Restart,
Detailed reference “docker port mapping or start the container times wrong” https://blog.csdn.net/whatday/article/details/86762264
First, report the wrong situation
When using the yum command, you cannot parse the yum source, and an error occurs:

​​
Second, report the cause of the error
The machine cannot parse the yum source, for three reasons:
(1) The machine can not access the Internet! Please check the network configuration to make sure that you can surf the Internet and then look at the second situation. A simple point is ping a public network IP, such as ping 114.114.114.114 if ping does not work, is not on the network. If you can ping it, that would be the second case.


(2) DNS configuration problem! Nslookup www.baidu.com
nslookup www.baidu.com
nslookup www.baidu.com
nslookup www.baidu.com
nslookup www.baidu.com
nslookup www.baidu.com


(3) The machine can access the Internet, DNS configuration has also been configured, but still cannot resolve yum source, then you can change to a yum source and try again.
​​
Three, can’t access the Internet solution
(1) Check the network card name and enter the command:

(2) Start to modify the network information configuration file, open the configuration file, and enter the command:

vi /etc/sysconfig/network-scripts/ifcfg-Name of the network card
e.g:vi /etc/sysconfig/network-scripts/ifcfg-ens33


(3) Change ONBOOT=no to ONBOOT=yes

4. DNS configuration error solution
(1) This problem is caused by yum’s inability to resolve the domain name corresponding to the remote packet management library even though it has been connected to the Internet during the process of package installation. Therefore, we only need to add the IP address corresponding to DNS to the network configuration. Open the configuration file and enter the command:

vi /etc/sysconfig/network-scripts/ifcfg-Name

(2) Append DNS at the end of the file:

DNS1=8.8.8.8
DNS2=4.2.2.2

(3) Restart the network and enter the command:

ifup Name
e.g:ifup ens33

Error: requesting member ‘*’ of ‘*’, which is a non-class type ‘*’

Code:
if (-1 == munmap (buffers. Start, buffers. Length))

error:
error: request for member ‘start’ in ‘buffers *’, which is of non-class type ‘buffer ‘, which is of non-class type ‘buffers’, which is of non-class type ‘buffers’
error: request for member ‘length’ in ‘buffers’, which is of non-class type ‘buffers’

reason:
Primarily, it is a pointer, but the use of “.” when referring to its members is used as a general variable, which would result in this compilation error.
Of course there are other reasons for this compilation error,
For example, variables are defined but not defined before they are used, and so on

modified:
if (-1 == munmap (buffers)
-> start, buffers-> length))