When I use the open keyword in F#
module AnotherModule
open myFSharpModule
Can this be thought of as a mixin in Ruby or a trait in Scala? I was thinking the other day how i wish that F# had these features, but then it occurred to me that the open keyword may be the same thing. In a way, it just copies the referenced module into the module you are defining.
In F#, open is just importing declarations to be accessible from the scope you're importing them.
It does not make those declarations part of your module, it's just so that you can reference them without qualification from within your module.
The equivalent in Scala is import, in Ruby it's require.
Related
I developed a PowerShell module that relied on a .NET Assembly for some operations.
I refactored this module to not need that Assembly and noticed some strange behavior, which blocks me from removing the class at last:
Add-Type -TypeDefinition "public interface ICanTalk { string talk(); }" -Language CSharp
class Talker : ICanTalk {
[string] talk() { return "Well hello there"; }
}
If you run this commands interactively, it will succeed.
But as soon as I run it "en-bloque" in ISE or from a psm1 file, it will throw an error, stating it cannot find the interface defined in the Add-Type call.
I can reproduce the problem in both Windows-PowerShell and PowerShell Core (6.0.2)
What is the reason for the different behaviour and how can I tackle it?
To complement your own answer:
PowerShell class and enum definitions are parsed before execution begins and any types referenced in such definitions must either be:
loaded into the current session beforehand.
[only partially implemented as of Windows PowerShell v5.1 / PowerShell Core 7.3.1]
loaded via a using module / using assembly statement at the very
top of the file.
using module already works, but only if the referenced types are themselves PowerShell class / enum definitions.
As of PowerShell 7.3.1, types loaded from assemblies - whether via a module containing assemblies imported with using module or using assembly to directly load an assembly - aren't yet detected.
See the following GitHub issues:
#3461 (using module) and #2074 (using assembly)
#6652 - a meta issue tracking all class-related issues.
Allowing using assembly to detect .NET types at parse time has been green-lighted in GitHub issue #3641, and the necessary work is being tracked as part of GitHub issue #6652 - but it is unclear when this will happen, given that the issue hasn't received attention in several years.
The workaround in the meantime is to load the referenced types via a separate script beforehand, by using the module manifest's NestedModules entry (which can also be used to dot-source *.ps1 files).
Note: The ScriptsToProcess entry would work too, but the scripts it references are dot-sourced in (loaded into the current scope of) the caller, not the enclosing module.
With types from compiled code (including ad hoc-compiled code with Add-Type), that works too, because such types invariably become available session-globally, but it is conceptually cleaner to use NestedModules, because it dot-sources scripts in the enclosing module's scope
Outside of modules, the workaround is similar:
Put your class definition in a separate .ps1 file.
In your main script, define or load the types that your class definition depends on, and then dot-source the separate script file, which ensures that all its dependent types have already been loaded.
In a pinch, you can also use Invoke-Expression (which should generally be avoided), as shown in this answer.
Apparently PowerShell will read the file and handle class-definitions before executing the code.
To solve this problem, the Add-Type needs to be put into an own script file, which is run before the module loads (or in ISE, just run the code before running the class definitions).
This can be accomplished by using ScriptsToProcess from the PSD1 file.
Kudos to #TheIncorrigible1 for putting me on the track.
Why not defining all classes in C# in a separate file, than add it as
Add-Type -path MyClasses.cs
This way it will work with older PS versions
If you define -PassThru and bind the Add-Type to a variable, you can use the variable to examine what all is being added.
could you advise how to search for built-in methods in laravel? For example I want to find controller's method validate() provided by the Illuminate\Http\Request and see how it works
You need to use IDEs (for example, PhpStorm) that provide such features. Look for "Go to declaration/definition" commands for the IDE you are using.
If you don't use IDE that supports jumps like that you can use external tools (I personally use Exuberant Ctags) to index your project's folder and generate tags file for all the classes, methods etc. But this approach will require additional setup from your part.
You can use debugger to trace your code in real time. But it requires for PHP debugger (like xdebug) to be set up and an IDE that supports debugging.
Lastly you can search for classes or methods you are interested in yourself. Laravel utilizes PSR-4 for autoloading, so the namespace of any class can easily lead you to the correct file inside /vendor/laravel/framework/src.
Intellisense suggestion list doesn't include properties and methods from imported module object, unless i use them once in the importing module.
If it's the supposed behaviour, do Cloud9 team have a future plan for improvement?
I need to use one module, I created previously using vhdl in another module and I cant find any info on how to do this. I'm forced to use maxplus2, and the only thing I found there is that I can create include file there (will have .inc extension), but I still cant get it included in my second module. I've spent the whole morning searching for this info but found nothing.
Can anybody help me with it?
You don't.
VHDL doesn't have include files, it avoids that whole horrid disastrous unreliable mess.
VHDL uses separate compilation, and good VHDL tools (not all of them!) track all the dependencies correctly without includes or Makefiles.
So you compile your other modules into a library - maybe "my_modules" - or if you don't specify a library, just compile it, it'll go into the default library called "work".
Then in your main module you name the libraries (except "work" which is always there)
library ieee;
library my_modules;
and name the things (modules, packages) you want from them (except "work" ...)
use ieee.numeric_std.all;
use my_modules.all;
and you can now use whatever you want from these libraries. The simplest way to use a module is "direct entity instantiation" - searching this and "VHDL" will show you how.
Or you can declare a component in your main module with the same ports as your other module, and the correct module will replace the component at elaboration (VHDL term for linking). Where you would need a component is if you haven't written the library modules yet - i.e. top down design... otherwise direct entity instantiation is simpler.
For now, ignore "my_modules" and just use "work" - when you get to a big design, use libraries to organise it, e.g. keep hardware and testbenches separate.
Brian has the right answer for you. Something I'd add which is related to your question in that it's something else people use include files for:
packages are VHDL's way of sharing data-types, constants, functions and procedures.
I am using a class module in my project. I made an EXE of the project. But this EXE gives error when I run this on another PC... even in mine PC, if run from another folder.
I get following error - 5 - Invalid procedure call or argument.
Can somebody guide me how to use the Class module while making EXE..?
A class module is analogous to a form module or a standard module (which is called just "module") in VB6. Basically, anything that has its own code window is a module. Class modules are saved with a .cls extension.
The probable reason for your error is that you can't see the class at the point you're attempting to use it.
Your question could mean several different things. Please give me a list of all the projects (maybe you have just one, but you could have more), all the forms, all the standard modules (just called "modules"), and all the class modules you are using. That will help me understand better how to answer your question.