Skip to content

Instantly share code, notes, and snippets.

View bvssvni's full-sized avatar

Sven Nilsen bvssvni

View GitHub Profile
// rustc 0.10-pre-nightly (7bda3df 2014-04-02 17:51:48 -0700)
// host: x86_64-apple-darwin
//
// Compile with
// RUST_BACKTRACE=1 rustc lib.rs --crate-type=rlib
#![allow(unreachable_code)]
pub fn foo() {
fail!("hello");
@bvssvni
bvssvni / gist:10579832
Created April 13, 2014 11:23
Idea: Type match in Rust
/// Returns true if T is int, otherwise false.
fn is_int<T: Num>(num: T) -> bool {
match <T> {
int => true,
_ => false,
}
}
/// Returns true if T impls Clone.
fn is_clone(val: T) -> bool {
compute : Integer -> Integer
compute x = if (x `mod` 2) == 0 then x `div` 2 else 3 * x + 1
traverse : Integer -> List Integer
traverse 1 = [1]
traverse x = traverse (compute x) :: x
ERROR:
collatz.idr:7:35:
test : List String -> String
test xs = ?something
%dynamic "./../target/x86_64-apple-darwin/lib/libidrisfs-ba8d5852-0.0.dylib"
getSizeInt : IO Int
getSizeInt = mkForeign (FFun "sizeof_int" [] FInt)
WARNING: Cannot load './../target/x86_64-apple-darwin/lib/libidrisfs-ba8d5852-0.0.dylib' at compile time because Idris was compiled without libffi support.
Resolving dependencies...
Configuring cabal-install-1.18.0.3...
/var/folders/_t/g72k9vzd30b5svvyd1nxpwp40000gn/T/56759.c:1:12:
warning: control reaches end of non-void function [-Wreturn-type]
int foo() {}
^
1 warning generated.
Building cabal-install-1.18.0.3...
Preprocessing executable 'cabal' for cabal-install-1.18.0.3...
Resolving dependencies...
Configuring cabal-install-1.18.0.3...
/var/folders/_t/g72k9vzd30b5svvyd1nxpwp40000gn/T/57145.c:1:12:
warning: control reaches end of non-void function [-Wreturn-type]
int foo() {}
^
1 warning generated.
Building cabal-install-1.18.0.3...
Preprocessing executable 'cabal' for cabal-install-1.18.0.3...
@bvssvni
bvssvni / Main.idr
Last active August 29, 2015 13:59
Rust & Idris
module Main
-- %dynamic "./../target/x86_64-apple-darwin/lib/libidrisfs-ba8d5852-0.0.dylib"
%include C "idrisfs.h"
%link C "idrisfs.o"
getSizeInt : IO Int
getSizeInt = mkForeign (FFun "sizeof_int" [] FInt)
-- describes an Integer representation of Bools
-- that also specify how many bits are used
data BitVector : Integer -> Integer -> Type
-- I want to make sure that the value of the integer
-- is always less than 2^first_argument.
-- Is this possible?
-- takes two Bool and return an Integer.
pairOfBoolsToInteger : Bool -> Bool -> BitVector 2 Integer