Skip to content

Instantly share code, notes, and snippets.

View amanjpro's full-sized avatar

Amanj Sherwany amanjpro

View GitHub Profile
@amanjpro
amanjpro / SimpleShell.hs
Last active January 28, 2017 16:45
A very simple shell in Haskell, still lots of things to do
import System.Posix.Process
import System.Posix.Types
import System.Directory
callSystem :: String -> [String] -> IO ()
callSystem "cd" args = setCurrentDirectory $ head args
builtinCommands :: [String]
builtinCommands = ["cd"]
f1 :: Int -> Int -> Int
f1 x y = let f2 :: Int -> Int -> Int
f2 x z = x + y + z
in let f2 :: Int -> Int -> Int
f2 y z = if y == 10 then x + y + z else f2 10 9
in f2 0 10 + y + x
f2 :: Int -> (Int -> Int, Int -> Int)
@amanjpro
amanjpro / ScalaMacros.scala
Last active August 29, 2015 14:17
Scala, macros and function/method application
/**
* In Scala methods/functions can be called in different ways.
* Here are some possible ways, for the following function/method:
*/
def m(n: Int): Int = n + 2
// C-like function/method calls
m(2)
@amanjpro
amanjpro / implicitClasses.scala
Last active August 29, 2015 14:17
Scala's implicit classes
// Let's define a class
class Animal(val kind: String)
// We have a utility class, which defines eats for Animal
class AnimalUtils {
def eats(p: Animal): String = ...
}
// We can call eats like that:
AnimalUtils.eats(new Animal("sheep"))