fay Could not find module `Control.Applicative' - fay

foo.hs
import Control.Applicative
then
fay foo.hs
returns
Could not find module `Control.Applicative'
It is a member of the hidden package `base'.
Use -v to see a list of the files searched for.
Is applicative programming possible in Fay?

Fay doesn't have type classes. We figured that in case someone wants to use an applicative they can implement the operators monomorphically. This would lead to name clashes if we provided some default applicative.
See this wiki page for more info on the status of type class support.

Related

How to Find Available Implicit Conversions for a Given Type in Scala

I am writing an autocompleter (i.e., code completion like in Eclipse or IntelliJ) for a domain specific language that is a subset of Scala. Users frequently use implicit conversions to hide the more advanced features of Scala like options or Scalaz disjunctions.
I am looking for a way, either at compile time or runtime, to acquire a list of implicit conversions available for a receiver (i.e., for the ‘x’ in ‘val y = x.foo’). So, I have two specific questions:
Is there some library that, given the type of a receiver, can find all the implicit conversions that the compiler could use to turn that receiver into another type?*
How is the identification of available implicit conversions actually done by the Scala compiler? I am not sure where in the source to look to find it; some documentation about how the compiler does this or the location in the source where it does it would also be very helpful.
*: As you might have guessed, I plan to use the resulting list to get all the available fields and methods of all the types the given variable could be implicitly converted to so that the autocompleter can suggest them all to users. If there’s an even more direct way to do that, that would be great too.

Type-class/implicit discoverability in Scala

In Scala, is there a way to "discover" all the type classes in scope; or more generally, all the implicits in scope? In ghci, :info Monad shows all the available Monads, and :info Maybe shows all the available type classes for Maybe, I wonder if something similar exists in the Scala.
No, Scala does not have something like that. There are a few compiler options as "-Xlog-implicits" that print a bit more information, if implicits are not applicable. But there is nothing to list all implicits available in a certain context.
One could try to do this via macros, but even the macro api does not provide a direct way to do that. There is access to the typer via the compiler API and implicit search. But this API is very complicated.

Scala JSR 223 importing types/classes

The following example fails because the definition for Stuff can't be found:
package com.example
import javax.script.ScriptEngineManager
object Driver5 extends App {
case class Stuff(s: String, d: Double)
val e = new ScriptEngineManager().getEngineByName("scala")
println(e.eval("""import Driver5.Stuff; Stuff("Hello", 3.14)"""))
}
I'm unable to find any import statement that allows me to use my own classes inside of the eval statement. Am I doing something wrong? How does one import classes to be used during eval?
EDIT: Clarified example code to elicit more direct answers.
The Scripting engine does not know the context. It surely can't access all the local variables and imports in the script, since they are not available in the classfiles. (Well, variable names may be optionally available as a debug information, but it is virtually impossible to use them for this purpose.)
I am not sure if there is a special API for that. Imports are different across various languages, so bringing an API that should fit them all can be difficult.
You should be able to add the imports to the eval-ed String. I am not sure if there is a better way to do this.

How to find documentation for Map

I'm trying to find documentation of the Map.toList method in Scala but looking at documentation this is a trait : http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Map . So how can I find the documentation for scala Map? WHen I instatiate a Map am I just instantiating the trait ?
Trait scala.collection.immutable.Map is a contract. It's valid for all implementations, so its documentation is a documentation for any immutable scala Map.
In current implementation method Map.apply (Map(a -> b, c -> d, ...)) creates HashMap for more than 4 elements.
There are also classes Map1 - Map4 for 1-4 elements. Also there is a singleton EmptyMap.
But this behavior could be changed in next scala versions in case there will be better implementation for general purpose.
It is defined in Predef. Also its source might be useful.
Traits cannot be instantiated. They are abstract by definition. If they're actually fully implemented, they can (appear to) be instantiated by creating an anonymous type at the point of instantiation:
val x = new FullyImplementedTraitName { }
As to your main question, the documentation for scala.collection.Map should tell you everything you need to know. When you have the full frameset for the ScalaDocs displayed the filter text field at the upper left allows you to narrow down the class and package list by entering a the name (or portion thereof) you're looking for.

Where is subsetOf in scala collections?

I'm at a loss on this one...
Looking at a Set in Scala collections, I see that there is a method called subsetOf. But when I try to find where it is in the actual .scala source code (I've looked in Set.scala, GenSet.scala, SetLike.scala etc...) I can't find it!!!
Which trait actually defines that method? Or am I missing something?
If you click on function in scaladoc, you may see where is it defined:
The scala API specifies:
Definition Classes: GenSetLike
When you're looking at the API page, click the method entry to expand it. You'll see more information, including the "Definition Classes".
If you look at the source for GenSetLike.scala, you'll see it:
def subsetOf(that: GenSet[A]): Boolean = this forall that