Skip to content

Instantly share code, notes, and snippets.

View morteako's full-sized avatar

Morten Kolstad morteako

  • Oslo
View GitHub Profile
@morteako
morteako / prolog-types.pl
Created November 7, 2017 12:12
INF3110 - Prolog - Oblig
% Implementing some rules about type theory in prolog.
% This combines some of the curriculum about types and subtypes from Eyvind's lectures with
% some SML stuff and of course Prolog.
% If you find any mistakes : send an email to morteako@student.matnat.uio.no
% 1a
% Define facts so that
% int is a type,
% number is a type
@morteako
morteako / Main.hs
Last active November 11, 2017 01:56
module Main where
import Control.Monad (guard)
import Data.Char (isLower,isUpper,isDigit)
data Symbol = C Char | V Char
data Equation = Equ String String String deriving Show
type Substitution = (Char , String)
type Unifier = [Substitution]
module Main where
import Data.Char (toLower)
import Data.List (foldl', sortBy)
import Data.Map.Strict (Map, (!))
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
shift xs = last xs : init xs
concatReverse xs = xs ++ reverse xs
f n = mapM_ putStrLn $ concatReverse $ fmap concatReverse $ (replicate n '#':) $ take n $ iterate shift $ take n $ '#' : repeat ' '
g n = mapM_ putStrLn $ ((++) <*> reverse) $ fmap ((++) <*> reverse) $ (replicate n '#':) $ take n $ iterate ((:) <$> last <*> init) $ take n $ '#' : repeat ' '
main = do
f 5
{-# LANGUAGE InstanceSigs, ScopedTypeVariables, DeriveFunctor #-}
-- Typekonstruktører
data TwoInts = TwoInts Int Int deriving Show
data TwoAs a = TwoAs a a deriving (Show, Eq, Functor)
data TwoDiffs a b = TwoDiffs a b deriving (Show, Functor)
(define nested '(((1) 2) 3 (4 (5 6))))
(define (deep-map proc tree)
(cond ((null? tree) '())
((list? (car tree))
(cons
(deep-map proc (car tree))
(deep-map proc (cdr tree))))
(else
(cons
{-# LANGUAGE RecordWildCards #-}
import Data.List (unfoldr)
import Data.Map.Strict (Map, (!?))
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
data Rute = Hvit {erAapning :: Bool} | Sort
deriving Show
import Data.List
main' =
readFile "a.txt" >>=
print
. sum
. map (length . concat . filter blank . dropWhile blank . dropWhileEnd blank . group)
. transpose . filter (not.blank) . transpose . lines
where blank = all (==' ')
{-# LANGUAGE RankNTypes #-}
module Main where
import Data.Monoid
newtype Adder = Adder
{ unAdder :: forall b. Monoid b => Int -> (Int -> b) -> b }
@morteako
morteako / TypeSeqCalc.hs
Created June 13, 2018 19:36
Sequent Calculus for propositional logic, implemented in Haskell's type checker
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
import GHC.TypeLits
import Data.Proxy
import Data.Type.Equality