This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type 'a SimpleType= F of (int ->'a-> 'a) | |
let get a = F(fun req -> id) | |
[<GeneralizableValue>] | |
let oops2<'T> : SimpleType<'T> = get "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object looksLikeAFunction{ | |
def apply(s:String):Int=1 | |
} | |
object nowAFunction extends Function[String,Int]{ | |
def apply(s:String):Int=1 | |
} | |
object TestMethods { | |
implicit def functionToAnother(f:Function[String,Int]):Function[Int,String] = | |
(i:Int)=> f(i.toString()).toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val xxxx={ println("initializing xxxx");1} | |
def getOne(x:Int):Int= 1 | |
println(getOne(xxxx)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fibs@(h:tfibs)= 1:2:zipWith (+) fibs tfibs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = do resp <- simpleHTTP request | |
case resp of | |
Left x -> print ("Error connecting: " ++ show x) | |
Right r -> | |
case rspCode r of | |
(2,_,_) -> | |
print $ ( valFromObj "statuses_count" | |
=<< decode (rspBody r) :: Result Int) | |
where | |
request=Request {rqURI = uriSadache, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simpleGet uri error ok = | |
do resp <- simpleHTTP req | |
either error | |
(\r -> | |
case rspCode r of | |
(2,_,_) -> ok (rspBody r)) | |
resp | |
where req=request urii | |
urii =fromJust $ parseURI uri | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
class Monad64 a ma mb | ma mb -> a where | |
(>>==) :: ma -> ( a -> mb) -> mb | |
data Maybe64 a = Just64 a | |
|Nothing64 | |
deriving Show | |
instance Monad64 a (Maybe64 a) (Maybe64 b) where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Error(msg:String) | |
val one:Either[Int,Error]= Left(1) | |
val two:Either[Int,Error]= Right(Error("oops")) | |
val result=for(a<-one.left; t <- two.left) yield a + t | |
// defined class Error | |
// one: Either[Int,Error] = Left(1) | |
// two: Either[Int,Error] = Right(Error(oops)) | |
// result: Either[Int,Error] = Right(Error(oops)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I really do not like using the syntax that removes points | |
scala> List("one","two") foldLeft ("") (_+_) | |
<console>:6: error: missing parameter type for expanded function ((x$1, x$2) => x$1.$plus(x$2)) | |
List("one","two") foldLeft ("") (_+_) | |
^ | |
// Int ??? | |
scala> List("one","two") foldLeft ("") ((_+_):(String,String) => String) | |
<console>:6: error: type mismatch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Error[+E,+A](e:Either[E,A]) { | |
def flatMap[B,EE>:E](f:A => Error[EE,B]):Error[EE,B] ={ | |
Error(e.right.flatMap(a=> f(a).e)) | |
} | |
def map[B](f:A=>B):Error[E,B]={ | |
Error(e.right.map(f)) | |
} | |
def toOptionLoggingError():Option[A]={ | |
e.left.map(m => {error(m.toString); m}).right.toOption | |
} |