However, I have since had a reason to come back to the Semantic Web. I had a problem where I wanted to have a Graph Database for a project on early Medieval Irish genealogies. I wanted an easy to use text based format for storing the data that was also well-known enough to be easily consumed by anyone who might want to use the data. In this case, much to my surprise, Semantic Web technologies were the easiest to use and were suited to the task.
One of the reasons for this is that I constrained the problem to something I could deal with. I was not attempting to model the entire Web, which is what, I believe, the Semantic Web community was attempting to do. This made the problem tractable, the solutions much clearer, and their benefits manifest. Additionally, unlike a random website that did not really want to invest much in metadata, I had a reason for using this particular technology.
So, I had a reason to use the technology. How does this all fit together?
The Resource Description Framework is the basis for all the other technologies in the Semantic Web/Linked Data. However, RDF had a rather rough beginning because it was created right around the same time as XML which as all the rage back in the early 2000s. This created RDF/XML and became the standard way in which RDF was expected to be created and consumed. Unfortunately, RDF/XML is verbose and does not actually fit the Graph all that well. People really did not like it. Thankfully, there are now several formats available but the one I chose was Turtle which is both terse but human readable.
Since I was basically creating this database by hand, I wanted to have to input the least amount of information. One of the benefits of Semantic Web technologies is that you can create logical schemas. In this way, you can apply logic to your data. To do this, you will need to create what is called an Ontology using the Web Ontology Language (OWL). An Ontology serves two purposes. First, it describes the logical implications of your data. Second, it describes some of the kinds of data that is allowed in certain positions. Unlike a SQL Schema, an Ontology does not restrict how data is stored or what types data are. It just stores the logical relations of the data and what implications can be drawn from a certain set of data. This is one of the strengths and weaknesses of OWL. Unlike SQL schemas, it will not stop you from storing data in a way that may be confusing (or even incorrect). This can cause confusion. There is a newly finished specification called the Shapes Constraint Language (SHACL) which does some of this.
The main problem with OWL is that there is a lack of tooling. For SQL, there are a couple of well-known and battle tested Open Source SQL systems (MySQL/MariaDB and PostgreSQL). There is only one (these are often called Triplestores) available for RDF that I know of Blazegraph which has the limitation of not supporting all of the OWL 2 specification. While this is annoying, there is Stardog, while it is closed source, it supports all of the OWL 2 specification and it has a limited Community Edition which you can use. I use Stardog because my database will probably never grow to the point of needing anything other than the Community Edition but you will need to take this in to consideration when thinking about tooling for this.
For a long time, RDF was, to be honest, rather inert. It existed but you had to figure out for yourself how to find it, store it, and search it. In 2008, the SPARQL specification fixed that. There is now a standard query language for RDF and Triplestores. Honestly, I found the query language specification one of the easiest to read that I have ever encountered. You can pretty much understand it from the examples given in the text of the specification.
One of the strengths here is that you do not find yourself having to use ORMs and other mechanisms to paper over syntax differences between commercial databases. If your Triplestore supports SPARQL, you can rest easy that it will work in mostly the same way across different Triplestores.
I have found working with Linked Data and Semantic web technologies rather fun. This probably has to do with the fact that I am working on a personal project that I find interesting. Additionally, I am working on something that is much more constrained than attempting to model the entire Web. However, I think over the years the Linked Data/Semantic Web story has developed rather nicely if slowly. There is a general lack of open source tooling, especially around a Triplestore that fully supports all the standards.
Would I use this for production services? If you have lots of heterogeneous data that you want to integrate together, yes, I would use it. For your normal everyday CRUD, maybe not but I would not dismiss it out of hand.
]]>Spoilers Ahead
]]> Once Rey has Luke’s Father’s lightsabre and has the map to where he has gone into hiding after Kylo Ren, his former student, has turned to the dark side and killed Luke’s fledgeling Jedi Academy, she goes to meet the Jedi anchorite himself. She goes to Skellig Michael, which is a site of an early Irish monastery. This shows a striking understanding of the role of the mystic and the anchorite in early Ireland and the scene evokes this to great effect.One of the most interesting features of early Irish Christianity is its embrace of late Antique forms of retiring from civil life into a more contemplative one. For instance, Kildare begins with the form kil- which originally comes from Latin cella or monastic cell (see cell). The pervasiveness of this element in place names in Ireland is an instance of just how powerful monastic style of Christianity was on early Irish thought and society. Although, one must be careful as many of the main monasteries in Ireland were very much involved in the daily lives of the dynasts around them (see Transformation of the Irish Church in the Twelfth Century, Marie Therese Flanagan, pp. 118-168). For instance, many abbots of powerful monastic houses were appointed by powerful secular families in the area of the monastery. However, for the early period (600 to 800AD), we have a set of hermits who exhibit clearly some Jedi-like attributes.
One of the most famous of these, of course, is St. Columba, who went into exile on Iona after causing a great battle over a book which he copied from his master, which is something his biographer, Adomnán, seems to miss out but it could be a legend to cover up the actual events which led to the battle. While on the other hand Luke goes into a hermit lifestyle after his failure with Ben Solo, the going into exile after a great personal tragedy is the same. However, unlike Luke who does not want to be found before the Force sends Rey to him, St. Columba collected followers and performed miracles (see Life of St Columba, Adomnán of Iona, ed. Richard Sharpe; also there is a great new edition here).
More Luke-like in this sense is the founder of one of the most influential monasteries of early Ireland, Cóemgen of Glendalough. Here, according to his hagiographer, he lived a life very close to nature and would often times spend years alone in the wilderness in deep contemplation and prayer and who went on to found the monastery of Glendalough. Although, again caution is necessary because much of the nature poetry so often found in early Irish literature has been, possibly wrongly, attributed to hermit figures like Cóemgen (see The Origin of Irish Nature Poetry and, as counterpoint see, ‘Early Irish “nature” Poetry”, Donnchadh Ó Corráin in Sages, Saints and Storyteller: Celtic Studies in Honor of Professor James Carney, Donnchadh Ó Corráin, Liam Breatnach and Kim McCone eds; also Blackbirds, cuckoos and infixed pronouns: another context for early Irish nature poetry, Patrick Ford in Celtic connections: proceedings of the Tenth International Congress Of Celtic Studies: volume one, language, literature, history, culture / edited by Ronald Black, William Gillies and Roibeard Ó Maolalaigh). Other instances of this can been found in Conversing with angels and ancients, Joseph F Nagy.
While the above are only two of the many instances of hermit saints with mystical powers, there are many more to be found in the early Irish literary corpus. J. J. Abrams uses this background (physical, historical, and mystical) to great effect when he uses Skellig Michael to highlight Luke’s journey from Return to the Jedi to the end of The Force Awakens. The austere conditions of the islands reflect the deep spiritual and mystical training that Luke will need to face Ben Solo (Kylo Ren) and rebuild the Jedi order (and fulfil his destiny to refound a great monastic order) with Rey and possibly Finn who is another great allusion to early Irish literature, which I will leave to someone more qualified than myself in matters Finn in the next two movies. Just to anticipate a bit on Finn. Fionn mac Cumhaill was a great warrior but always on the fringes of society much like Finn in the movie if you see Finn go from deep inside the First Order to an outsider as part of the Resistance. To delve into this more, see The wisdom of the outlaw : the boyhood deeds of Finn in Gaelic narrative tradition by Joseph F Nagy.
With the above in mind, the final scene works within the context of early Irish Christianity. It shows how, while Star Wars is usually interpreted within the Buddhist context, it can also be interpreted within an early Irish Christian context. J. J. Abrams reminds us that we do not need to look outside the Western tradition to find The Force.
With that, I am very much looking forward to the next two instalments.
]]>I just wanted to let everyone know that the British Library now has a means like the Library of Congress to link to specific books. This is called the “British National Bibliography” and is available at http://bnb.data.bl.uk. This should ease the problem of some books not being available from the Library of Congress. For instance, Bechbretha has a URL of http://bnb.data.bl.uk/id/resource/012025232. You can place extensions at the end to get various formats: for example http://bnb.data.bl.uk/id/resource/012025232.rdf will get you the RDF version of the document.
Things are now to the point where we can really drop most citation frameworks and go straight with something that looks like my citation proposal.
]]>To give away the game before starting, I would like to say that this book would be an excellent addition to the library of anyone who has an interest in the pre-history of Ireland. While it is not my area of expertise, it illuminated much which I had already gleaned from the writings of others; however, this was done in a highly engaging and effective way. One of the main advantages of this book is the way in which the key points are gathered at the end of each chapter which reminds the reader of all the foregoing material. This would easily make this a book which should appear in any Celtic Studies course. The additional factor which makes this book even more valuable is the easy style and humour of one who has an absolute command of the primary and secondary material. However, this is not a book without its flaws which will be discussed anon.
]]> To allow himself some kind of bounding box for his enquiry, Mallory chooses to take the reign of Niall Noígiallach as his terminus ante quem of his study. This nicely sets the boundary at about the point at which early Irish literature, broadly construed, begins to discuss historical matters rather than creation and group identity myths. At this point he asks the question: would a person in Ireland at this point consider themselves Irish? This might sound strange to the ear of a modern Irish person. This, however, is a key point: we have no idea and will never have any idea about the group identity of the people living in Ireland before the period of the Iron Age, where it becomes easier to imagine the people living then to be more like those about whom we read in the literature. Even, as Mallory discusses, DNA does not help in many cases and is often misused and misconstrued as evidence in claims about “Celticity”.In terms of flaws, the first chapter is one of them. The quip attributed to Carl Sagan comes to mind: “to make an apple pie by scratch, you first have to create the universe”. This is what the first chapter does. It takes you from the beginning of the universe up to c. 10,000 years ago with the advent of the first evidence of human settlement in Ireland. This was unnecessary. While a geologic description of Ireland would have nicely set the stage for the rest of the book, this is, as the adage goes, “over-egging the pudding”. While the chapter was rather amusing, it could probably have been removed or heavily revised to a more straightforward account of the geology of Ireland around the time of human settlement.
The second chapter discusses the first colonists to Ireland, which, as noted, was the last colonized area of Eurasia. Much of this chapter covers the debates around how the colonists first arrived. The most likely of these are Scotland, the Isle of Man, or Wales. These are rather obvious although Brittany is also discussed as a possible launching point.
The third chapter covers the first farmers and the introduction of farming techniques into Ireland. Much of the material culture between Ireland and Britain at this time point to a heavy cross-sea connections (and some to Brittany). Again, while there is some controversy surrounding the details, it seems to be agreed that, once farming was introduced by outside peoples, the farming colonists simply outbred and outfed their neighbours. Additionally, the farming communities and the previous inhabitants did not have much mutual contact.
The fourth chapter covers the more mysterious and controversial Beaker-culture which spread across Europe after 2500 BCE. This brought metallurgy (copper, silver, gold) to Ireland and connected Ireland and all of the British Isles into a large cultural network which extended from Norway to Spain and Ireland to Hungary. While the invasion hypothesis has lost favor, it is not entirely clear how the Beaker-culture came to Ireland and there are very few Beaker-culture artefacts left in Ireland. This leads to the question: how could the Beaker-culture have such an outsized effect on Ireland? The introduction of metallurgy is my preferred answer in this case. Transforming rock into metal is one of the most powerful things a human being can do and if you can do this, it gives you tremendous power over others both in the sense of weaponry and ritually.
The fifth chapter covers the Bronze Age in Ireland. This was a more quiescent period in pre-historic Ireland. The waves of people more or less stopped but the interchange between the Continent and the British Isles continued unabated. Hillforts begin to be constructed and there seems to be a rise of a warrior culture. This could be construed, especially for the late Bronze Age, as an early “Celtic” culture. However, as I, and many scholars maintain, “Celtic” is a purely linguistic term and not a very good one at that as the controversy over the term “Celtic”, now seems to be entering its third decade.
The sixth chapter is devoted to the Iron Age and is one of the longest in the book. While we are now a far cry from Jackson’s “The Oldest Irish Tradition: A Window on the Iron Age”, much of what appears in the Iron Age is kept and brought forward in to the historical period. However, the quiescence continues into this age. There is no evidence for an invasion, only a continuation of incremental improvements to technology. Hallstatt and La Téne cultures seem to have been imported and assimilated without difficulty. This would argue for a deep cultural connection between the British Isles and the Continent. One must remember here that the sea is not a barrier but highway and boat making was a more widespread skill than within the last few hundred years in the British Isles.
In chapter seven we get a very condensed version of Leabor Gabála Érenn. This relies heavily on the work of John Carey for translation and some commentary and Kim McCone for the “Irish Old Testament” interpretation. While this is laudable, it does not mention the seminal articles by Scowcroft (see here and here) which cover a large amount of ground concerning the manuscript tradition. These articles are the touchstone for any discussion of Leabor Gabala Érenn and probably should have been included. Mallory seems to be leaning heavily on Celtic Studies here but he still shows a deft hand at communicating the basic story without getting lost in the details.
Chapter eight is where much of the value of this book derives. This chapter covers the recent discoveries using DNA evidence, which is mainly derived from what can be extracted from ancient bones and teeth. There are two sets of contradictory conclusions that can be made and many of the sensationalist claims (such as those surrounding Niall Noígiallach himself) should be taken with a rather large dose of salt. This kind of DNA evidence shows that cultural change cannot be predicated on changes in DNA. Most of the populations of Europe carry very similar haplogroups and there is little in the way of evidence that Ireland is substantially different than any other group in Europe since the last Ice Age. Much of the debate around ancient DNA evidence has a tinge of race based thinking behind it which makes me rather uncomfortable especially since the technology and the current interpretive techniques lack subtlety and maturity. More evidence and less hyperbole is needed.
The last chapter which contains the meat of the book is the chapter devoted to language. Here, he takes the reader through the various evidence from Ptolemy’s geography to the language of the Old Irish period. Most of this is what you would get in an undergraduate course on Celtic as a language group with a focus on Irish. The only place where Mallory and I differ is that he believes that there was a group of Brittonic speakers in the southeast of the country at the time of the Ptolemaic geography. I would say that this may show that Insular Celtic was still in the latter stages of breaking up rather than being Brittonic as such.
To conclude, this is an excellent book and brings a much needed synthesis of all the current knowledge in various areas surrounding pre-historic and near historic Ireland. It brings a corrective tone to the sensationalist claims of DNA enthusiasts (rarely it seems scientists themselves). This book is well worth the cover price and should be in the syllabus of any beginning course on Celtic Studies.
Christopher Guy Yocum ORCID
]]>Open Access began mostly in the sciences as a reaction to the fact that science publishers were continuing to mark-up the amount it cost to purchase journals without thinking of the stagnating and declining library budgets. This has lead to a confrontation between libraries and publishers in the sciences. The outcome of this continuing debate is two forms of Open Access called “Green”, preferred by libraries and university administrators, and “Gold”, preferred by the UK government and publishers. A good discussion of the pros and cons can be found here.
My main concern comes from the fact that, whatever kind of Open Access you choose, they are backed by mandates from funders and university administrators. This is the most problematic part of Open Access from my point of view. The tradition is that scholars knew their audiences and were free to write and research for them in whatever venue they best knew. Now, however, there is a thick layer of “research managers” who are ever more insistent that they know scholarship better than those who actually do the scholarship or research. This, coupled with the statistically dubious impact factor, is now the driving narrative around Open Access.
For the Humanities, all of these debates are being foisted upon them as, in their reality, nothing much has changed. Monographs and journals are still reasonably priced. Scholarship continues just as it has for many, many years. The reality is that most readers who maybe interested in the output of Humanities scholars prefer physical books to ebooks. This means that there just is no market or interest in Open Access online monographs or books.
The point is that university administrators are now using Open Access as a tool of control over the scholastic process, which was always managed by the academics themselves. This is causing a slow moving power struggle between them with Open Access getting a bad name in the Humanities in the process. This is mainly an administrative over-reach and a dismissive attitude towards the Humanities, whether justified or not, by those in positions of influence or power. Although, I will maintain that Humanities scholars have remained myopic in the face of the rise of new communications technologies.
I guess my new stance is that Open Access is a good idea but the implementation is awful and seriously needs re-evaluation in light of the principles of Academic Freedom and a respect for those who actually engage in research and scholarship, which seems missing from the current climate of debate.
]]>There are many different features which mark the change from Old to Middle Irish. Much of this is discussed in much more detail in Kim McCone’s “A First Old Irish Grammar and Reader” pp. 173—217. I will give a small précis of this here. For a more full account for verbs, see Kim McCone “The Early Irish Verb” pp. 163—240. A full analysis by Liam Breatnach is detailed in “Stair na Gaelige” pp. 221—333. The main problem with Breatnach’s analysis is that it is entirely in Modern Irish so unless you know that language first, or you enjoy typing and trust Google Translate, it will be inaccessible to you.
]]> Loss of Final syllablesIn some noun classes, you will notice a loss of final syllables or they will fall into ə (schwa). The canonical example is daltae (fosterling, later student) in the nom. and acc. will become dalta. If you check Thurysen “Grammar of Old Irish” pg. 179, you will notice that the a in daltae is optional, which is marked dalt(a)e. In Middle Irish, the e is lost and the a is mandatory. This will also happen in verbs that end in -ae more generally.
The deutertonic forms of compound verbs disappear and they are re-analysed as their prototonic forms with weak simple verb endings. For instance, do-léici “casts/throws” becomes teilg(eann) from the prototonic form -teilci (he casts). In a sentence, you may see this teilgam “I cast” for Old Irish do-léiciu (or do-léicim). In addition, the deponent verbs also disappear entirely and are re-analysed in the same way as the compound verbs. In the future tense, the f-future becomes the norm, as it is in Modern Irish.
The infixed pronoun completely disappears, are confused, or petrified. They are replaced by the independent pronoun. For instance, a very common petrification is at-beir “he says it” for “he says” with obvious object or object pronoun for the verb. For instance, at-beir-som rúin frisin ingin “he says a secret to the girl”. The infix pronoun at- is not necessary and just means “he says [it] a secret to the girl”. Please also note that the emphatic -som is the only way to tell if it is “he” rather than “she” in Old Irish which is why, when loss of final syllables like above occur, the independent pronoun is pressed into service.
The neuter gender for all noun classes disappear and become masculine.
The leniting and nasalizing relatives clauses disappear to be replaced with relative marker “a”.
The comparative of adjectives are generally used in Old Irish with the verbal construction ol-daas (or placed in the dat.), which means “than it is”, notice the hiatus here (see Thurysen GOI pp. 477—478 and pg. 232). This becomes petrified and begins breaking down. Ol-daas becomes naas then later níos and ná in Modern Irish. For example, feicfidh mé thú níos déni in Modern Irish (I will see you later).
So far, you will not notice much in the way of spelling changes. What you will notice is that beginning and medial c becomes g. So, cach becomes gach, oc becomes ag, ocus comes agus, which are the same as in Modern Irish.
These are the most notable changes from Old to Middle Irish. The references at the beginning will refine and explained these so I would recommend you read those as well as this.
]]>In any case, that brings me to the format for these citations. Many of them have: the author, publisher, date, place of publication, and page number. In the “bad old days”, these were necessary to allow the reader to trace arguments and facts. Now, however, we have the greatest machine ever created to do that for us: the URL and the Internet. The first thing you may ask is: how do you cite books then? Well, you may have not noticed but the Library of Congress now has a permalink. For instance, The Road to Judgment. So, in the “Yocum Style Citation” (YSC), which I just made up, you would put “Stacey, Robin Chapman. http://lccn.loc.gov/93047677. pg. 55” in a footnote. For a journal article, the DOI, Handle, Jstor stable URL plus page number. If you don’t want to use the Library of Congress permalink for books, you can use Worldcat’s (http://www.worldcat.org/oclc/29519665) instead. Unfortunately, the British Library does not yet have permalinks for its collection. What happens if the URL is too long? DOI has a shortening service for DOIs. OpenURLs are notoriously awful for being long. I don’t have a solution to that but, given that DOIs are pretty much de facto now, it won’t matter too much. You could use a shortened url in the text and a full URL in the bibliography, which are still required under YCS but are generally the same except that you put full URLs instead of any shortened ones that are in the text.
Why do this? First, I am tired of the rather complex and arcane rules of citations in the Humanities. Every journal seems to have its own preferred style and it makes submitting to these journals difficult and if you get turned down and resubmit it else where, you have to completely change everything. Second, URLs are good enough now to cite with. The Internet is not leaving us any time soon. If you are that paranoid, just require the full citation in the bibliography.
It is high time we change to make it easier for everyone. If I want to look up a book citation, I can just go to the url and get the book from my local library or if it is a DOI, Handle, or Jstor stable URL, I can get the article right away. If I don’t have access to the internet that second, it’s not like I cannot get access later.
Teaching the arcane rules with attached URLs just does not make much sense. It duplicates information and makes it harder on the student or writer. It makes the humanities look out of touch and old. For medievalists, like myself, even the manuscripts now have URLs and can be referenced via them so instead of using some off-the-cuff MS citation method because each archive is different and each has a different way of cataloguing their collections, you can use the URL to point to the exact MS page you are talking about.
Anyway, I will probably be putting this into practice myself soon as I get the chance.
]]>I am still interested in the option route as well though. I tried to implemented but the type checker went a bit crazy so I will need to think about it more before I try it again.
Thanks!
]]>Thanks for this! I am still unsure about the empty. How do I fire the function in that case without something of the proper time to pass in?
]]>module type MONAD =
sig
type 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
val return : 'a -> 'a t
end
You will notice here that I am declaring a module type and not a module. Basically, I want to build monads out of things. Thus, Monad in OO terms is an abstract base class. So, if we want to have a “kind of” Monad, we have to build it. In any case, the type 'a t
is the type system wrapper around a polymorphic value. Basically, the type system wraps the value in a type so that it can be manipulated at the type level rather than at the value level. return
is kind of an odd way to put it but it “return”s a Monad out of a value of some kind (as has been pointed out by pozorvlak, mote is a better term for values of that type and is a common mistake in Monad tutorials); we don’t care what kind (or type) the value is. bind
is a way for the user to bind a function to a Monad. What you will get is the Monad feeding the value into the function and expecting a new Monad from the function then it will automatically return that Monad.
So, you can create different kinds of Monads to do different things and one of the side-effects is that side-effects are encapsulated within the Monad itself. This means that you can do things which are not “pure” functional programming within a purely functional system (this isn’t strictly true either). As you can see with bind
, you will always return a Monad. However, I can hear you saying, “but how do I get values out of a Monad?” Don’t worry you can do that by having a function like this:
val access : 'a t -> 'a
This function is some times called “run” as well. What it does is it asks the Monad for its computation (aka “a thunk”) as the Monad writer can put off actually doing the computation until this stage in the processing. So, with that knowledge, let’s attempt the next stage:
module type STATE =
sig
type t
val empty : t
end
Again, this is an abstract base class for “State” and it allows you to define your own state using a functor (I should write another thing on functors). Basically, I don’t want to constrain the kinds of StateMonads and just let my users define what kind of state they need. So, bringing this together with the MONAD declaration above:
module type STATE_MONAD =
functor(State : STATE) ->
sig
include MONAD
val access : 'a t -> 'a
val put : State.t -> unit t
val get : State.t t
end
Ok, again another declaration with no real code, please be patient all will be revealed. This has access and put and get functions. The access function, actually does the computation of functions that are bound within the Monad. The put and get is something I am still trying to get my head around but it basically allows you to use the StateMonad as a variable store. You can store things in it like a variable and retrieve the information and return it.
So, now on to some Real Code:
module StateMonad : STATE_MONAD =
functor(State : STATE) ->
struct
type state = State.t
type 'a t = state -> ('a * state)
let bind m f =
fun s ->
match m s with
| (x, s') -> f x s'
let return a = fun s -> (a, s)
let access m =
match m State.empty with
| (x, s) -> x
let put s =
fun _ -> ((), s)
let get =
fun s -> (s, s)
end
So, lets break this down. The functor allows the user to set what kind of state they want. I will demonstrate this below. The next bit is type 'a t = state -> ('a * state)
. This defines the actual type that is wrapped inside the StateMonad. Basicaly it said “This Monad is a function which takes one state and translates that state into a value and the next state”. Thus, when you put a state in the StateMonad via return
, it returns just what it says on the tin a function which takes a state and return a tuple of a value and the state. The next function bind
binds a function to the Monad and the monad calls the last function it created (in this case the “m” in the code) and matches the output of “m” with the expected tuple which is then passed to the next function in the chain. The access
function takes an empty state and that fires the function chain to come to a final state and value then the final value is returned.
Now, the put
and get
functions. I am not sure I actually understand these as well as I should so I will tell you now that if what I say is wrong, please let me know. So basically put
creates a degenerate return function which puts the value in the same kind of wrapper as a function. The get
passes back a function which fires immediately and gives you back it’s value. I am completely unsure of how exactly this works but it seems to work in practice. If someone could enlighten me, that would be wonderful.
So, now I will present a trivial example: IntStateMonad.
module IntStateMonad = StateMonad(
struct
type t = int
let empty = 0
end
)
This tells the StateMonad what kind of state the user wants. This basically fills in the functor State from above. I am still slightly unsure if the empty value is really necessary or if there is some other way I can get the underlying function to fire without it. So here is an example:
let _ =
let blah = IntStateMonad.return 1 in
let blah2 = IntStateMonad.bind blah (fun i -> IntStateMonad.return (succ i)) in
print_endline (string_of_int (IntStateMonad.access blah2))
So, can we do something more Haskell like in this instance? Yes, with the “perform” notation that is provided by pamonadcustom, which uses camp4 to parse ocaml and do syntax transformations. So we can do this like so:
let return = IntStateMonad.return
let _ =
let blah =
perform with IntStateMonad.bind in
a <-- return 1;
b <-- return (succ a);
return b
in
print_endline (string_of_int (IntStateMonad.access blah))
So you have to bind the return and bind functions to something that is accessible by the pa_monad syntax. Otherwise, it takes care of interleaving the binds then it returns the resulting Monad which you can run (or access…whatever you prefer to call it).
As for get
and put
, you can use it in this way:
let _ =
let blah =
perform with IntStateMonad.bind in
a <-- return 1;
b <-- IntStateMonad.put 5;
c <-- return (succ a);
d <-- IntStateMonad.get;
return (c + d)
in
print_endline (string_of_int (IntStateMonad.access blah))
So, there you have it. This is a Monad which keeps track of the state for you and will return the evaluated functions in a type wrapper. This will also get and store state like a variable wrapped inside the bound function calls. All side-effects are explicitly handled inside the Monad and Leibniz gets to smile. Who said philosophy was useless?
UPDATE Added information on motes and clarified some stuff on side-effects in a purely functional programming language.
]]>As Camomile uses functors extensively, you need to know how they work so you can follow the code example below. However, it is fairly straight forward once you get your head around it (it took me a while to figure this out which is why I am putting this here).
open CamomileLibraryDefault
open Camomile
module UTF8Decode = Camomile.CharEncoding.Make(UTF8)
let _ =
try
let changed = UTF8Decode.decode Camomile.CharEncoding.utf8 "神奈川大学" in
UTF8.validate changed;
print_endline "yes!";
exit 0
with
| UTF8.Malformed_code ->
print_endline "no!";
exit 1
]]>