In Isabelle is there a way to ensure that a type variable could be an interpretation of a locale?
I know that I can, for example, ensure that a type variable is of a particular class:
isValid :: 'a::ord =>: bool
However, I can't find how to extend this idea to a locale:
class address ....
<snip>
locale Message =
fixes
sender :: "'message => 'address::address" and
receiver :: "'message => 'address::address" and
isValid :: "'message => bool"
locale Filter =
fixes
fiterFunc :: "'filter => 'message::Message => filterResult"
The Filter locale gives errors such as Undefined class. Is there a way to write such an expression?
Locale interpretation is described in the tutorial on the locales and in the reference manual. One of my previous answers on SO contains relevant references: link.
From section 3.3.6 in the reference manual: "Sorts have a very simple inner syntax, which is either a single class name c or a list {c1, ..., cn} referring to the intersection of these classes". Therefore, it is not possible to use a locale as part of a sort of a type variable. The locale interpretation mechanism is different.
Related
As a complete Dart beginner coming from python and javascript, I find this behavior quite strange:
var user = {'name': 'John Doe', 'birth_y': 1980};
2021-user['birth_y'] // is 41
But if the operator is on the right.
user['birth_y'] + 41 // error
The error:
Error: The operator '+' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '+' operator.
user['birth_y'] + 41;
^
From the error, one guesses that for maps with mixed types, entries have type 'Object', Yet:
user['birth_y'] is int // true
user['birth_y'].runtimeType // int
This behavior is also exhibited by lists of mixed types,
What am I missing?
Dart does a statically analysis of your program before running it. In this analyze phase, it will look at the data type of your variables and see if it is statically safe.
In your case you have this Map:
var user = {'name': 'John Doe', 'birth_y': 1980};
Since your Map contains different types of values, Dart will try to see which data type can be used for all your values. In this case, the only thing String and int shares is the Object type. So user is being analyzed to be of the type Map<String, Object>.
This means that when you get a object from user, the only thing the analyzer can be sure about is it is of the type Object.
So when you do:
user['birth_y'] + 41
The analyzer will assume you get a Object which does not have the + operator.
You should in general not use Map as some kind of object which contains different data types. Instead create a class which makes it possible to write type safe code.
I am trying to create a dictionary of functions with symbols as keys but I am getting an error. I have tried the following:
functions = Dict{
:gauss => (v::Float64)->gauss(v, 0.0, 1.0),
:sin => (v::Float64)-> sin(v),
:nsin => (v::Float64)->(-sin(v)),
:cos => (v::Float64)-> cos(v),
:ncos => (v::Float64)->(-cos(v)),
:tanh => (v::Float64)->tanh(v),
:sigm => (v::Float64)->sigmoid(v),
:id => (v::Float64)->id(v)
}
The error I am getting :
ERROR: LoadError: TypeError: in Type, in parameter, expected Type, got Pair{Symbol,getfield(Main, Symbol("##105#113"))}
Please let me know what I am doing wrong. Thanks for the help in advance.
I figured the{} need to replaced by ().
As you found out your yourself, the {} brackets indicate type parameters whereas the paranthesis indicate a constructor call.
Note, that the ::Float64 type annotations aren't necessary for your functions to be performant. Think of them more as a user interface restriction; that is users won't be able to call your methods with non-Float64s. However, if you want to specify types explicitly, you could also specify the type of your dictionary explicitly as such Dict{Symbol, Function}(...). However, since you don't initialize the Dict empty, Julia will figure out the best type based on your input (symbol function pairs).
I am trying to understand elm's type signatures. What does this function return exactly? It appears to be a function that accepts no arguments and returns ...
route : Parser (Page -> a) a
As a learning exercise for myself I'm going to try to answer this. Others will chip in if I get something wrong.
I'm sure you are used to something like
type Person = Adult String | Child String Age
Child is a type that takes two parameters. Parser is the same. But it's definition is pretty formidable
type Parser a b =
Parser (State a -> List (State b))
type alias State value =
{ visited : List String
, unvisited : List String
, params : Dict String String
, value : value
}
That said, you see how Parser is ultimately a wrapper around a function from a State to a list of States. Ultimately it is going to be passed a List of 'unvisited' strings or params; it will progressively 'visit' each one and the result will be combined into the final 'value'.
Next, note that while Parser takes two type parameters - a, b - parseHash is defined
parseHash : Parser (a -> a) a -> Location -> Maybe a
So, your original
route : Parser (Page -> a) a
is going to have to be
route : Parser (Page -> Page) Page
to type check.
To return to your original question, therefore, route is a Parser (which is a very general object) that encapsulates instructions on how to go from one Page to another, and can be used - via parseHash - to tell you what Page to go to next, and that is of course what you would expect from a router.
Hope this gets you started
Is there some way to specify a "not" type in flow? For example,
compact = (input: Array<any>): Array<notFalsey> => input.filter(i => !!i);?
Currently, there is no syntax to specify a "not" type, like $Not<string>, which would be anything but a string.
For your specific compact example, Flow's library definition for Array.prototype.filter does include a special case for using the Boolean function as the filter function. So you can write
const compactedArray = myArray.filter(Boolean);
v0.31.0 will ship with a magic type $NonMaybeType, so you will be able to write a compact function with return type Array<$NonMaybeType<T>>.
I'm trying to do the following simple thing: given a topological space, extract its topology and view it as a poset. For that, I imported Topology.thy and Orders.thy and tried something along these lines
fun undtop :: "'a top ⇒'a partial_order" where
"undtop T = (leq ::"T ⇒ T ⇒ bool" where
"leq x y = (x ⊆ y)")"
where 'a top is the type 'a set set and partial_order is of type 'a=>'a => bool (the theory Orders.thy defines a class class partial_order) . The idea was that some T of type a' top should give the topology and then undtop would pick such a T and associate a partial order leq, viewed as a map T => T => bool. Clearly this is not how it works, so I'd like to ask
1) How would you define a function that picks each T of a certain type and defines a new function with domain T?
2) How to specify that this T of type 'a top is a topology, and not just a random collection of subsets, i.e how do I tell Isabelle that it should obey the axioms of the locale "topology" in Topology.thy?
Thank you for the support, as a beginner I'm still struggling with the syntax and the way Isabelle operates.