Can we express () in terms of a Record in Idris? - idris

Can we express () i.e Unit type in terms of a Record in Idris ?

You can create a record with no fields.
record Unit where
constructor MkUnit

Related

Does calling a user defined function twice in select query lead to inefficiency?

I have a simple table where people's birthday are been stored. I also have a simple scalar user defined function where the function takes a "Date" object (birthday) and returns an int (Age). I wrote a query which tries to select every entry that has an age of 17.
In the "select" query, "dbo.calculateAge(Birthday)" were written twice, so I was just wondering, does this mean that "calculateAge" function will be called twice? Does this leads to inefficiency? If yes, is there a better way to write this query?
My Query:
My Table:
I choose not to include implementation of the "calculateAge" function here because I don't think it is useful to the question I'm asking.
does this mean that "calculateAge" function will be called twice?
No, just once. But to be sure, make sure your function is declared as deterministic.
Does this leads to inefficiency?
No.
If yes, is there a better way to write this query?
It's fine.

default value : where are they stored on the Database Odoo?

where the default value are stored in Odoo?
for example the supplier tax on the product product_supplier_taxes_rel
ir.values :
Holds internal model-specific action bindings and user-defined default
field values. definitions. This is a legacy internal model, mixing
two different concepts, and will likely be updated or replaced in a
future version by cleaner, separate models. You should not depend
explicitly on it.
For more information refer this
Go to
Setttings => Actions => User-defined defaults

Using entity framework and MSSQL AVG() function

I have this line of code (using MSSQL):
double avg = db.MyTable.Where(x => x.RecordDate < today).Select(z => z.value).Average();
I wonder if this is translated to SQL AVG() function or the Average() run on client side ?
This table contains 50,000 records per day and I prefer to let the database calculate the average and pass back only a single value.
And, how can I see the SQL query sent to the database ?
If you don't enumerate your queryable, yes, average will be done on db side.
You can also simplify your code. Select is not needed, there's an overload for average taking an Expression<Func<T, double>> (or a decimal, int...) as parameter.
double avg = db.MyTable.Where(x => x.RecordDate < today).Average(z => z.value);
and they are quite many ways to see the sql generated, you can google for sql generated linq, or take a look here, for example

efficiency of using 'class' in Fortran 2003?

Fortran 2003 supports data polymorphism by using class, like:
subroutine excute(A)
class(*) :: A
select type (A)
class is ()
...
type is ()
...
end select
end subroutine
My question is: if I need to call this subroutine a huge amount of times, whether it will slow the code down because of the SELECT statement?
SELECT TYPE is typically implemented by the descriptor for the polymorphic object (CLASS(*) :: A here) having a token or pointer or index of similar that designates the dynamic type of the object. Execution of the select type is then like a SELECT CASE on this token, with the additional complication that non-polymorphic type guards (TYPE IS) are matched in preference to polymorphic guards (CLASS IS).
There is some overhead associated with this construct. That overhead is more than if the code did nothing at all. Then again, code that does nothing at all is rarely useful. So the real question is whether the use of SELECT TYPE is better or worse execution speed wise to some alternative approach that provides the necessary level of functionality (which might be less than the full functionality that SELECT TYPE provides) that your code needs. To answer that, you would need to define and implement that approach, and then measure the difference in speed in a context that's relevant to your use case.
As indicated in the comments, an unlimited polymorphic entity is essentially a type safe way of storing something of any type. In this case, SELECT TYPE is required at some stage to be able to access the value of the stored thing. However, this is only a rather specific subset of F2003's support for polymorphism. In more typical examples SELECT TYPE would not be used at all - the behaviour associated with the dynamic type of an object would be accessed by calling overridden bindings of the declared type.

What is the use case for Merge function SQL Clr?

I am writing a CLR userdefinedAggregate function to implement median. While I understand all the other function which I have to implement. I can not understand, what is the use of the merge function.
I am getting a vague idea that if aggregated function is partially evaluated ( i.e. evaluated for some rows with one group and the remaining in other ) then the values needs to be aggregated. If its the case is there a way to test this ?
Please let me know if any of the above is not clear or if you need any further information.
Your vague idea is correct.
From Requirements for CLR User-Defined Aggregates
This method can be used to merge another instance of this aggregate
class with the current instance. The query processor uses this method
to merge multiple partial computations of an aggregation.
The parameter to merge is another instance of your aggregate and you should merge the aggregated data in that instance to your current instance.
You can have a look at the sample string concatenate aggregate. The merge method add the concatenated strings from the parameter to the current instance of the aggregate class.