ghc backpack

Voor diegene die iets unieks willen en daarbij opzoek naar een geweldige manier om hun backpack reis te beginnen is het volgen van de zijderoute een goede optie. Ruim 2000 jaar geleden bereikte zijde voor het eerst Europa. De Romeinen werden verliefd op deze zachte, fijne stof en betaalde er grof geld voor. Lange tijd was zijde dan ook zelfs waardevoller dan goud. De route veranderde vaak maar de meest voorkomende liep van het huidige Xi’an tot aan het huidige Istanbul. De zijderoute was dan ook liefst 8000 kilometer lang en het duurde maanden voordat de bestemming was bereikt. Toen China zich begon terug te trekken achter de recent gebouwde Chinese muur en de Europese landen zeeroutes ontdekte werd de zijderoute steeds minder gebruikt. Tegenwoordig is het volgen zijderoute nog steeds een fascinerende ervaring. Het plannen van de route, de visa en het vervoer, kost weliswaar wat tijd maar je krijgt er veel voor terug. Door landen als Oezbekistan, Kirgizië, Georgië, Azerbeidzjan, Turkmenistan en natuurlijk China zie je de meest uiteenlopende landschappen en culturen.

De meeste reizigers die de zijderoute volgen leggen niet de hele route af maar slechts een gedeelte. Ook dit is nog heel leuk om te doen. Je zou zowel vanuit Europa naar China kunnen gaan of juist de zijderoute volgen aan het einde van je Azie reis maar wij kiezen voor deze beschrijving voor de eerste optie. Je kan de zijderoute op eigen houtje kunnen uitvoeren maar hou er rekening mee dat het niet zomaar een reis is.
solo backpack luzonQua vervoer, visa, accommodaties en dergelijke zou je veel moeten regelen.
wunderlich backpackEr zijn ook vele aanbieders van rondreizen rond deze route.
nike acg backpack steel cityBekijk deze mogelijkheden onder andere op Sawadee.nl en Koningaap.nl.
soyuz laptop backpack

Als je zelf alles wilt regelen heb je misschien meer aan onze tips over vliegtickets naar Azië.Backpack, a new system for mix-in packages in Haskell, has landed in GHC HEAD. This means that it has become a lot easier to try Backpack out: you just need a nightly build of GHC. Here is a step-by-step guide to get you started. Download a GHC nightly Get a nightly build of GHC. If you run Ubuntu, this step is very easy: add Herbert V. Riedel's PPA to your system and install :
pleasanton backpack uk This will place a Backpack-ready GHC in /opt/ghc/head/bin/ghc.
vans realm backpack jewel blueMy recommendation is you create a symlink named to this binary from a directory that is in your PATH.
zerg backpack If you are not running Ubuntu, you'll have to download a nightly or build GHC yourself.

GHC supports a new file format, bkp files, which let you easily define multiple modules and packages in a single source file, making it easy to experiment with Backpack. This format is not suitable for large scale programming, but we will use it for our tutorial. Here is a simple "Hello World" program: We define a unit (think package) with the special name main, and in it define a Main module (also specially named) which contains our main function. Place this in a file named hello.bkp, and then run ghc hello.bkp (using your GHC nightly). This will produce an executable at main/Main which you can run; you can also explicitly specify the desired output filename using filename. Note that by default, ghc creates a directory with the same name as every unit, so main won't work (it'll give you a linker error; use a different name!) A Play on Regular Expressions Let's write some nontrivial code that actually uses Backpack. For this tutorial, we will write a simple matcher for regular expressions as described in A Play on Regular Expressions (Sebastian Fischer, Frank Huch, Thomas Wilke).

The matcher itself is inefficient (it checks for a match by testing all exponentially many decompositions of a string), but it will be sufficient to illustrate many key concepts of Backpack. To start things off, let's go ahead and write a traditional implementation of the matcher by copy-pasting the code from this Functional Pearl into a Regex module in the Backpack file and writing a little test program to run it: If you put this in regex.bkp, you can once again compile it using ghc regex.bkp and invoke the resulting executable at main/Main. It should print True. The previously shown code isn't great because it hardcodes String as the type to do regular expression matching over. A reasonable generalization (which you can see in the original paper) is to match over arbitrary lists of symbols; however, we might also reasonably want to match over non-list types like ByteString. To support all of these cases, we will instead use Backpack to "functorize" (in ML parlance) our matcher.

We'll do this by creating a new unit, , and writing a signature which provides a string type (we've decided to call it Str, to avoid confusion with String) and all of the operations which need to be supported on it. Here are the steps I took: First, I copy-pasted the old Regex implementation into the new unit. I replaced all occurrences of String with Str, and deleted splits and parts: we will require these to be implemented in our signature. Next, we create a new Str signature, which is imported by Regex, and defines our type and operations (splits and parts) which it needs to support: At this point, I ran ghc to typecheck the new unit. But I got two errors! Traversable null nonsense aside, the errors are quite clear: Str is a completely abstract data type: we cannot assume that it is a list, nor do we know what instances it has. To solve these type errors, I introduced the combinators null and singleton, an instance Eq Str, and rewrote Regex to use these combinators (a very modest change.)

(Notice we can't write instance Traversable Str; it's a kind mismatch.) Here is our final indefinite version of the regex unit: (To keep things simple for now, I haven't parametrized Char.) Instantiating the functor (String) This is all very nice but we can't actually run this code, since there is no implementation of Str. Let's write a new unit which provides a module which implements all of these types and functions with String, copy pasting in the old implementations of splits and parts: One quirk when writing Backpack implementations for functions is that Backpack does no subtype matching on polymorphic functions, so you can't implement Str Bool with a polymorphic function Traversable t => t a Bool (adding this would be an interesting extension, and not altogether trivial). So we have to write a little impedance matching binding which monomorphizes null to the expected type. To instantiate with , we modify the dependency in main: Backpack files require instantiations to be explicitly specified (this is as opposed to Cabal files, which do mix-in linking to determine instantiations).

In this case, the instantiation specifies that 's signature named Str should be filled with the Str module from . After making these changes, give ghc a run; you should get out an identical looking result. Instantiating the functor (ByteString) The whole point of parametrizing regex was to enable us to have a second implementation of Str. So let's go ahead and write a bytestring implementation. After a little bit of work, you might end up with this: There are two things to note about this implementation: Unlike , which explicitly defined every needed method in its module body, provides null and singleton simply by reexporting all of the entities from Data.ByteString.Char8 (which are appropriately monomorphic). We've cleverly picked our names to abide by the existing naming conventions of existing string packages! Our implementations of splits and parts are substantially more optimized than if we had done a straight up transcription of the consing and unconsing from the original String implementation.

I often hear people say that String and ByteString have very different performance characteristics, and thus you shouldn't mix them up in the same implementation. I think this example shows that as long as you have sufficiently high-level operations on your strings, these performance changes smooth out in the end; and there is still a decent chunk of code that can be reused across implementations. To instantiate with , we once again modify the dependency in main: We also need to stick an LANGUAGE OverloadedStrings pragma so that "acc" gets interpreted as a ByteString (unfortunately, the bkp file format only supports language pragmas that get applied to all modules defined; so put this pragma at the top of the file). But otherwise, everything works as it should! Using both instantiations at once There is nothing stopping us from using both instantiations of at the same time, simply by uncommenting both dependency declarations, except that the module names provided by each dependency conflict with each other and are thus ambiguous.

Backpack files thus provide a renaming syntax for modules which let you give each exported module a different name: How should we modify Main to run our regex on both a String and a ByteString? But is Regex.String.Reg the same as Regex.ByteString.Reg? A quick query to the compiler will reveal that they are not the same. The reason for this is Backpack's type identity rule: the identity of all types defined in a unit depends on how all signatures are instantiated, even if the type doesn't actually depend on any types from the signature. If we want there to be only one Reg type, we will have to extract it from and give it its own unit, with no signatures. After the refactoring, here is the full final program: Next time, I will tell you how to take this prototype in a bkp file, and scale it up into a set of Cabal packages. If you are feeling adventurous, try further parametrizing so that it no longer hard-codes Char as the element type, but some arbitrary element type Elem.