factorial :: Integral a => a -> a
factorial n
| n < 2 = 1
| otherwise = n * factorial (n - 1)
data Tree a =
Empty
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
-- From This | |
main :: IO () | |
main = withSocketsDo $ do | |
args <- getArgs | |
let port = fromIntegral (read $ head args :: Int) | |
sock <- listenOn $ PortNumber port | |
putStrLn $ "Listening on " ++ (head args) | |
sockHandler sock | |
-- To This |
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 (main) where | |
import Network | |
import System.Environment (getArgs) | |
import System.IO | |
import Control.Concurrent | |
import Control.Applicative | |
addCommand :: Handle -> [String] -> IO () | |
addCommand handle (x:y:_) = hPrint handle $ (read x :: Int) + (read y :: Int) |
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
;;; package -- summary | |
;;; Commentary: | |
;;; Alejandro Cabrera's init.el | |
;;; Code: | |
(require 'package) | |
(add-to-list 'package-archives | |
'("melpa" . "http://melpa.milkbox.net/packages/")) | |
'("marmalade" . "http://marmalade-repo.org/packages/") | |
(package-initialize) |
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
alejandro@rainbow-generator:~/haskell/ref-caut:[master *=]$ cabal run -- --target-lang c --output schema_c --input examples/atomicObjectBathroomMonitor.scm | |
Preprocessing executable 'ref-caut' for ref-caut-0.1.0.0... | |
(specification "bathroom monitor" "0.0.0" 9F28EC11DCB8345E305685813D8F849772BEDA02 | |
(builtin u8 60DBBD40B307AC819FF2A1BF0A7CF7C5D9E41309 1) | |
(builtin void CBF9E406F24683F7D894BF8F26AD3AC2E246AB6F 0) | |
(enum status 1 1 u8 8F9BE19357D113F37695FDFD8A646BD9228EBDE4 | |
(field open void 0) | |
(field closed void 1)) | |
(struct aoBathrooms 2 2 23B339D11E709BD1326D9CB8490D64E2CC742FB1 | |
(field upstairs status 0) |
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
-- Agda has a notion of hierarchical Sets. This corresponds to a type | |
-- universe where types that live in Set0 are "smaller" than those | |
-- that live in Set1 define a type Bool. `Set` is Set0. | |
-- Here, we define a boolean type that lives in Set. | |
data Bool : Set where | |
true : Bool | |
false : Bool | |
-- functions in Agda must be total. If we omit either of these |
This gist demonstrates solutions to HW 1.1 in multiple languages. Avoid reading if you'd like to solve it on your own. :)
Write a function is_older that takes two dates and evaluates to true or false. It evaluates to true if
the first argument is a date that comes before the second argument. (If the two dates are the same,
the result is false.)
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
(* This is a comment. You'll see a few of these. *) | |
(* This is a value binding. *) | |
val x = 1; | |
(* Names can be rebound/shadowed. This is not assignment. *) | |
val x = 2; | |
(* This is a value-binding with a type annotation. *) | |
val y : int = 1; |
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
irb(main):015:0> def fact(n) | |
irb(main):016:1> n == 0 ? 1 : n * fact(n-1) | |
irb(main):017:1> end | |
=> :fact | |
irb(main):018:0> fact(10) | |
=> 3628800 | |
irb(main):019:0> def facto(n) | |
irb(main):020:1> fact(n) | |
irb(main):021:1> end | |
=> :facto |