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
% 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 |
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 | |
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] |
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 | |
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 | |
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
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 |
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
{-# 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) |
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
(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 |
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
{-# 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 |
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
import Data.List | |
main' = | |
readFile "a.txt" >>= | |
. sum | |
. map (length . concat . filter blank . dropWhile blank . dropWhileEnd blank . group) | |
. transpose . filter (not.blank) . transpose . lines | |
where blank = all (==' ') | |
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
{-# LANGUAGE RankNTypes #-} | |
module Main where | |
import Data.Monoid | |
newtype Adder = Adder | |
{ unAdder :: forall b. Monoid b => Int -> (Int -> b) -> b } | |
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
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import GHC.TypeLits | |
import Data.Proxy | |
import Data.Type.Equality |
OlderNewer