Reference in Coq Lists library not found - coq

I'm trying to use the concat function as it appears in https://coq.inria.fr/distrib/current/stdlib/Coq.Lists.List.html. I tried the following:
Require Import Arith Coq.Lists.List.
Import ListNotations.
Definition CON (l : list nat):= (concat [[0]; l]).
but I get the error Error: The reference concat was not found in the current environment. I thought this should work since I've already imported the library, so I don't know where this error comes from.
I'm using version 8.4pl3 (January 2014). Could be a version issue?

concat was added in this commit. I think it was close to the end of the 8.4pl3 release so it was not pushed to the release, but rather to the next 8.5

Related

Cannot import value abs from module Data.Number

The abs method of the purescript-numbers package is documented here:
https://pursuit.purescript.org/packages/purescript-numbers/9.0.0/docs/Data.Number#v:abs
However, consider this simple code example which implements this method:
import Data.Number (abs, toNumber, isFinite, sqrt)
j :: Number
j = abs -32.5
This produces the following error:
Cannot import value abs from module Data.Number
It either does not exist or the module does not export it.
Is this a bug, or intended behavior?
What is the correct way to import / use the abs method of the Data.Number library?
My suspicion is that you're probably using PureScript compiler v0.14.x and a corresponding package set 0.14.x, but at the same time are looking at the latest versions of the libraries on Pursuit.
Just about a week ago, the new version of PureScript compiler 0.15.0 came out, and with it came many breaking changes (most notably, ES-format foreign modules), and as is tradition in such cases, the community took the opportunity to do some refactoring while we're at it.
One instance of such refactoring was moving the abs function (as well as many other functions) from the Math module (in the math library) to the Data.Number module (in the numbers library).
This means that if you're using PureScript 0.15 and higher, abs is in Data.Number, but if your version of PureScript is lower, the function is in the Math module.

Coq Import problems with power

It seems I can't get the Coq Import system right.
I found pow_succ_r in Coq.Arith.PeanoNat.
So I imported it and hoped it is usable
Require Import Coq.Arith.PeanoNat.
Print pow_succ_r.
I get the following error:
pow_succ_r not a defined object.
Notice the line Module Nat near the top of the documentation. It means that the subsequent declarations are inside the Nat module. So, you can access the symbol as Nat.pow_succ_r.
In general, if you are looking for a symbol, use the Locate command:
Locate pow_succ_r.
(*
Constant
Coq.Arith.PeanoNat.Nat.pow_succ_r
(shorter name to refer to it in current context is Nat.pow_succ_r)
*)

How to import the Library: Coq.Arith.PeanoNat in Coq?

I need to use the part of the standard library called Coq.Arith.PeanoNat (https://coq.inria.fr/library/Coq.Arith.PeanoNat.html).
I've tried either importing the entire Arith library or just this module, but I can't use it either way.
Every other library I've tried works just fine. When I do Require Import Bool. I compile and I can use it correctly. Upon Print Bool. I can take a look at all the functions inside in the next format:
Module
Bool
:= Struct
Definition...
.
.
.
End
When I do either Require Import Arith.PeanoNat. or Require Import Arith. I get this as immediate output:
[Loading ML file z_syntax_plugin.cmxs ... done]
[Loading ML file quote_plugin.cmxs ... done]
[Loading ML file newring_plugin.cmxs ... done]
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
When I ask Coq Print Arith.PeanoNat it outputs: Module Arith := Struct End, it seems to be empty. When I try to use anything from the library, for example le_le under boolean comparisons, I get the standard Error: leb_le not a defined object. I have updated Coq and the libraries, and I have no idea of what might be going on here. I'd appreciate your input in fixing this library problem.
If I am not mistaken, Require is the keyword to load a file. Import has to do with managing name spaces. Often they are used together, as in Require Import PeanoNat., but they are really doing two different things.
When coq files (DirName/FileName.vo) are loaded with Require, it is as if the contents of FileName.vo is wrapped in Module DirName.FileName ... End. Everyting defined in the file is then accessed with DirName.FileName.Name.
The file can itself have modules M inside of it, and to get to M's contents, one has to type DirName.FileName.ModuleName.Name1 etc.
Import is used to get all the definitions up to the top level. By doing Import DirName.FileName.ModuleName the module Name1 is now imported to the top level, and can be referenced without the long path.
In your example above, the file Arith/PeanoNat.vo defines the module Nat. Actually, that is all it defines. So if you do Require Import Arith.PeanoNat you get PeanoNat.Nat at the top level. And then Import PeanoNat.Nat will bring Nat to the top level. Note that you can't do Require Import PeanoNat.Nat because it is no .vo file.
Coq can sometimes find a .vo file without you having to specify the whole path, so you can also do Require Import PeanoNat. and coq will find the file. If you wonder where it found it, do Locate PeanoNat.
Coq < Require Import PeanoNat.
Coq < Locate PeanoNat.
Module Coq.Arith.PeanoNat
Another Nat is also available from another place than PeanoNat.
Coq < Require Import Nat.
Warning: Notation _ + _ was already used in scope nat_scope
Warning: Notation _ * _ was already used in scope nat_scope
Warning: Notation _ - _ was already used in scope nat_scope
Coq < Locate Nat.
Module Coq.Init.Nat
So, you don't Import a library, you Require it. You use Import to not have to use the full path name. I hope this helps you debug what is happening.
When I try Print Arith.PeanoNat, the output is slightly different: I get Module PeanoNat := Struct Module Nat End and then even though leb_le is not in scope, Nat.leb_le is.
(I run 8.5beta2 in case that's relevant).

IntelliJ IDEA warns about Scala imports instead of showing type info when importing object members

I have code similar to below
import sqlCtx.implicits._
val items = sc.parallelize(List(i1, i2, i3))
items.toDF().registerTempTable("items")
When I hover over items I would like usual behaviour - displaying type information. Instead I get warnings Avoid wildcard imports and Imports should be grouped together. I can get rid of the first by importing specific function, like
import sqlCtx.implicits.rddToDataFrameHolder
but I can't put import on top of the file what IntelliJ expects of me since it imports from an object that is created with the code and not preexisting. How to workaround it?
I use IntelliJ IDEA v. 15.0.3 with the latest Scala plugin.

Scala-IDE or Scala strange import behavior

I am working on a small Scala project. I have the following issue with 'import':
If, at the top of one of my files, I import two thing with these commands:
import main.Main._
import main.game.Game
^^^^
it gives me the following error message at the underlined 'main' word: "missing arguments for method main in object Main; follow this method with `_' if you want to treat it as a partially applied function" which is quite strange especially that it is just an import statement. And naturally no actual importing occures. At first I thought about semicolon inference quirks again but it is not the case. If I swap the two lines and write like this:
import main.game.Game
import main.Main._
then everythinng is fine.
Could anyone shed some light on that? Is it something special about Scala?
Presumably you have a main method in object Main. So after import main.Main._ main refers to this method instead of the main package. You could avoid it in several ways:
Change import order, as in the question.
Don't import the main method, as Daniel C. Sobral's answer suggests.
Explicitly say you want the top-level main package:
import _root_.main.game.Game
Following the normal Java package naming convention should avoid this problem in most cases, as you are unlikely to have members (or subpackages) called com or org (though net could be a problem).
You do have a method named main inside main.Main, don't you? Well, since you imported it, it has now shadowed the package by the name main. You can try this to confirm:
import main.Main.{main => _, _}
import main.game.Game
This will exclude main from being imported.