PureScript have lots of functions available like filter lenth and more. But how can we find the function that we need and its examples with implementation? I am facing problem solving exercises of the book purescript by examples. Any tips how show I go about solving those? Example in the book does not explain everythin.
Really, the most straightforward way would be to use the tooling that comes with the compiler through an editor plugin. You can use ?typehole to get the type of the type hole and get search results for relevant functions.
I also quite often type in a partial identifier and use the completion to look through the implementations, e.g. fil <complete to find various filter definitions.
For all newbie to PureScript who are following PureScript by example book this github link has all the solutions with updated libraries
https://github.com/kvsm/purescript-by-example
Related
Does purescript have something like Haskell's System.Plugins?
I need to create some 'generic interface' (sorry for this, I've been programming in object oriented languages for almost 15 years) that other developers will be able to use just by putting a module file in a plugins directory.
I wonder if it is possible since as far as I know Purescript does not have any metadata carried with types at runtime.
From a cursory glance, Haskell's plugins package is about dynamic loading of Haskell code. The similar concept in JavaScript is eval or adding a script element to the DOM.
You can make any type assumption for eval'd code using a foreign import or unsafeCoerce. However, you must take care to ensure that the assumption is correct.
I am not aware of a purescript package oriented around these sorts of plugins. In my estimation there would be too much variability in what a plugin could be to really have a sole package for it.
Are there any support for first-class patterns in Erlang?
f(SomeMagicPattern) ->
receive
SomeMagicPattern -> ok
end.
If the answer is no (support), do you know any other approach for achieving this? For example, using macros?
No, Erlang doesn't have first-class patterns out of the box.
There are two ways of implementing this:
Macros. Widely used, for example in testing tools like EUnit and PropEr. Say, EUnit has an ?assertMatch macro, which is in fact an example of first-class patterns:
?assertMatch({ok, _}, Result)
Parse transforms. Harder to write, but potentially more powerful, since using them you can access Erlang abstract code and rewrite it completely, in any way you desire. There's a nice link to a series of tutorials on parse transforms here: Is there a good, complete tutorial on Erlang parse transforms available?
As demeshchuk points out this is not the case.
There is however a proposal to add something similar to the language:
http://www.erlang.org/eeps/eep-0029.html
Whether or not this is a good idea is a completely different question...
There is a old computer language called APL. Could this be implemented in Scala as a DSL?
http://en.wikipedia.org/wiki/APL_%28programming_language%29
Someone could probably give a better answer than this, but this is my initial thought:
A Scala DSL should in theory be able to implement any programming language because it could build up an arbitrary structure representing the syntax, and then evaluate that.
A Scala DSL could not exactly replicate APL syntax for many reasons, one of which is that
'single quotes'
can denote a string in APL, but not in Scala. Also (from the wikipedia page)
×/2 3 4
wouldn't be valid Scala.
I don't know how close you could get, though...
A Javascript implementation exists here: https://github.com/ngn/apl
Hoogle allows you to search many standard Haskell libraries by either function name, or by approximate type signature. I find it very useful. Is there anything like Hoogle for Scala? Search in ScalaDoc 2 only finds types and packages by name.
There are plans to make the Hoogle interface work with multiple languages: http://code.google.com/p/ndmitchell/issues/detail?id=45
It's a pity that it does not even have an index like javadoc. Hoogle is nicer, though.
I use a personal search engine from Google to search the Scaladocs.
A search provider (searching with site: http://www.scala-lang.org/docu/files/api) in Firefox is another way to search the docs.
Both do not work well for the Scala 2.8. release – it's not indexed well enough to be useful – and works not with all operators. For example a search for Cons :: returns only nonsense.
Scaladoc for Scala 3 has Hoogle-like searches feature. You can try it out here.
It uses Inkuire search engine.
I use a lot of scala maps, occasionally I want to pass them in as a map to a legacy java api which wants a java.util.Map (and I don't care if it throws away any changes).
An excellent library I have found that does a better job of this:
http://github.com/jorgeortiz85/scala-javautils
(bad name, awesome library). You explicitly invoke .asJava or .asScala depending on what direction you want to go. No surprises.
Scala provides wrappers for Java collections so that they can be used as Scala collections but not the other way around. That being said it probably wouldn't be hard to write your own wrapper and I'm sure it would be useful for the community. This question comes up on a regular basis.
This question and answer discuss this exact problem and the possible solutions. It advises against transparent conversions as they can have very strange side-effects. It advocates using scala-javautils instead. I've been using them in a large project for a few months now and have found them to be very reliable and easy to use.