How can I manage multiple configurations of a single Haskell program? - configuration

What is an alternative to autotools in Haskell world? I want to be able to choose between different configurations of the same source code.
For example, there are at least two implementations of MD5 in Haskell: Data.Digest.OpenSSL.MD5 and Data.Digest.Pure.MD5. I'd like to write code in such a way that it can figure out which library is already installed, and didn't require to install the other.
In C I can use Autotools/Scons/CMake + cpp. In Python I can catch ImportError. Which tools should I use in Haskell?

In Haskell you use Cabal configurations. At your project top-level directory, you put a file with the extension .cabal, e.g., <yourprojectname>.cabal. The contents are roughly:
Name: myfancypackage
Version: 0.0
Description: myfancypackage
License: BSD3
License-file: LICENSE
Author: John Doe
Maintainer: john#example.com
Build-Type: Simple
Cabal-Version: >=1.4
Flag pure-haskell-md5
Description: Choose the purely Haskell MD5 implementation
Default: False
Executable haq
Main-is: Haq.hs
Build-Depends: base-4.*
if flag(pure-haskell-md5)
Build-Depends: pureMD5-0.2.*
else
Build-Depends: hopenssl-1.1.*
The Cabal documentation has more details, in particular the section on Configurations.

As nominolo says, Cabal is the tool to use. In particular, the 'configurations" syntax.

Related

C# with antlr4 parse mysql,use mysql-workbench grammars

I use antlr4 grammar is mysql-workbench.
https://github.com/mysql/mysql-workbench/tree/8.0/library/parsers/grammars
The cmd as follows
java -Xmx1024m -jar antlr4-4.7.2.jar -Dlanguage=CSharp -listener -visitor -o ./mysql -package MyAntlr4 MySQLLexer.g4 MySQLParser.g4
However,I miss the class MySQLBaseLexer, MySQLBaseRecognizer. How can I get the Class file。
These classes exist only in C++. You have to port them over to C# yourself. However, they are only support classes for a few things like predicates, server version etc. So, it should be fairly easy to do the translation. Also, it would be enough to only port the necessary parts. Not every helper function in those classes is required to use the MySQL grammar.

Composer autoload file before loading dependencies

One of the vendor packages I'm requiring exposes a function by autoloading it:
{
...
"autoload": {
...
"files": [
"functions.php"
]
}
}
Unfortunately it lacks multilingual support.
As I really like the function's fluent definition and I already have a drop-in multilingual alternative., I would like to use my drop-in replacement instead while still using the same function name. Luckily the package has implemented a function_exists() check, so I just need to declare my function before the package is autoloaded.
I know I could just reference a require before requiring Composer's autoloader, but are there any composer.json alternatives to accomplish this? Is there any way I can tell Composer to load a specific file first, before anything else?
More specifically I'm looking to override Laravel's unlocalized now() function to a localizable version. Since this question is also applicable to other applications and/or dependencies I kept my question quite generic.

packing and unpacking data structure with Perl6

on perl5 if someone want to parse binary file he has the pack/unpack utiltiy where he can convert binary structure to perl variables and vice verca ,
is there now a production equivlant for pack/unpack on perl6 ,as from the documentation i found that there are pack/unpack methods for Perl6 but they are experimental ,
does anyone know the status of those functions and if there are alternative to parse binary file which contains a list of records on perl6 ?
You are correct, the pack/unpack methods are experimental; there is currently no other method that is recommended in their place, however.
The experimental flag indicates that the Perl 6 dev team may change the interface. pack & unpack were marked in this way because there was not enough time to review and update the interface before the Christmas release in 2015-12.
I am using rakudo:
use experimental :pack;
pack("C*", [1, 2, 3]); => Buf:0x<01>
I am not sure this is correct use. I expect all bytes get packed in.

How to use mole manually in Visual Studio Express?

I searched for tags "Moles" and "Visual Studio Express", and found no questions. That probably means I'm the only person trying to use Express with Moles :)
In Express, there are no options such as "Add moles assembly", or "Add mscorlib".
I've managed to get the tutorial for the DateTime Y2Kbug working after manually adding a couple of references that would normally be handled by VS. So, that means that I can mole any of the pre-moled stuff in System or mscorlib, which will be useful.
My problem is that I cannot seem to mole any of my own classes or methods in the SUT. I don't believe that the compiler sees any of the .moles file that contains the assemblies to mole.
I proved (?) this by attempting to exclude DateTime from the Y2kbug tutorial, using:
<MoleGeneration>
<Types>
<Remove FullName="DateTime!" />
</Types>
</MoleGeneration>
But the "bug" was asserted as usual :)
Is it possible to generate non-System moles as I need them by using something I saw in this forum: stackoverflow.com/questions/6272217/microsoft-moles-dynamically-instrument
Call Microsoft.Moles.Framework.Moles.MoleRuntime.SetMole(Delegate _stub, object _receiver, MethodInfo method);
If I use the "SetMole" method, does that mean that I don't need "assembly" files which are not seen anyway? If so, would it be possible to give some examples of the use of "SetMole". (I'm not a techie.)
As suggested by Mike Christian, I used moles.exe OrigValueP.dll. This created OrigValueP.Moles.dll in the MolesAssemblies subfolder.
Add OrigValueP.Moles.dll as a reference to the test project.
View OrigValueP.Moles in the Object Browser. I now see MOrigValue.AllInstances. So that's a huge step forward.
However, I don't see any Moles equivalent of my method:
public string TestString() { return "Original value"; }
[Deleted lines relating to the command, "moles.exe OrigValueP.Moles.dll", because MC suggested I'm "attempting to mole the mole assembly".]
So, I have one question (which I will continue to try to answer myself): Why was there no Moled method for TestString()?
The Moles documentation states Moles is compatible with Visual Studio 2008 Professional or Visual Studio 2010 Professional or better. http://research.microsoft.com/en-us/projects/pex/molestutorial.docx
Don't forget that executing the moles compiler via command line requires that you perform compilation in the following order:
1. Target assemblies
2. Moles (against the target assemblies)
3. Test assemblies
The Moles Manual provides the following command line instruction:
http://research.microsoft.com/en-us/projects/pex/molesmanual.docx
Code Generation Command Line The Moles framework includes a command-line application that can generate the code by following the
instructions in .moles files or directly from assemblies. By default,
the command-line tool compiles the stub types and mole types into an
assembly and places it into a MolesAssemblies subfolder. The following
list shows examples of typical usage.
Generate mole types and stub types for a particular
assembly moles.exe assembly.dll Generate mole types and stub types
from an existing .moles file moles.exe assembly.moles Generate
mole types and stub types under a particular namespace moles.exe
assembly .dll /nf:MyNamespace Get detailed help about usage of
moles.exe moles.exe help
[This whole answer has been appended to the original question. Sorry for all the mess.]

Is there an Actionscript to ABC Bytecode parser?

So, I have an app where users should define ActionScript functions.
What do I need to get the string whritten by the user and convert it to bytecode so that I can use it with as3-commons-bytecode?
Edit
I don't think I was clear enough. I need to turn: if(!myValue) {...}
Into this:
...
findpropstrict private::myValue
getproperty private::myValue
not
iffalse L1
...
Because with this ^^^^ code, I can use as3-commons-bytecode to do what I need.
I took a look at this app's source code. It's very confusing, the project is old and the code is a mess, but it works. I need to find "where the magic happens". Can you show me the way?
You should use part of this project :
eval.hurlant.com/demo/#app=da4a&757d-selectedIndex=0
Check source , there is parser to ABC .
I'm not aware of any libraries that do this for you, but to achieve this functionality you should parse user's input into function names.
For example, you can call a function just by having it's name as a String like so:
var functionName:String = "myMethod";
function myMethod():void
{
trace("myMethod");
}
this[functionName](); //traces "myMethod"
Of course, if you wish to interpret advanced strings with getting/setting objects and their properties and any other user defined statements, that would require to write quite a sophisticated string-to-bytecode converter.
UPDATE:
There's also AS3Eval library that might do the job. Take a look at http://eval.hurlant.com/
There is a library for Haxe which makes it possible to compile Actionscript assembly language into ABC at runtime, but this is still lower-level than the Actionscript you normally write.
http://haxe.org/com/libs/format/abc
The most likely solution is a server or other process which can compile and return SWF content for you. Haxe has a very fast and straightforward compiler, but it may also be possible to use Tamarin or another solution for compiling AS3 on the server.
Actually, there is a runtime library for executing Haxe code, which again, is very similar to Actionscript. Might be worth looking into:
http://code.google.com/p/hscript/
What exactly want to do? To compile "string" the string must be something meanfull for the compiler such as package not a simply string ( like 'asdas ' ). If you don't wont to use flash/flex compiler you may compile AS to ABC with Ant or Haxe. But ther is a problem - how you will start this ABC?