This file contains hidden or 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
| case class Imm(stuff :Int) { | |
| def moreStuff(x:Int) = stuff + x | |
| } | |
| class Mut(stuff :Int) extends Imm(stuff) { | |
| var scary :Int = 0 | |
| override def moreStuff(x:Int) = {scary+=1; stuff+scary+x} | |
| } |
This file contains hidden or 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
| cond [a] {Infinite} :- | |
| [a] {a : [a] {Infinite}} | |
| cond [a] {NonEmpty} :- | |
| [a] {a : [a]} | |
| cond Maybe a {NonEmpty} :- | |
| Just a | |
| newtype Stream a = Stream ([a] {Infinite}) |
This file contains hidden or 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 MultiParamTypeClasses #-} | |
| {-# LANGUAGE FunctionalDependencies #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| {-# LANGUAGE ViewPatterns #-} | |
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE StandaloneDeriving #-} | |
| import Prelude hiding (tail, head) |
This file contains hidden or 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.Monoid | |
| import Data.Char (digitToInt) | |
| import Data.Foldable (foldrM) | |
| --- Part One --- | |
| -- Bind using the reader monad: | |
| -- x >>= k = \w-> k (x w) w | |
| -- head >>= foldrM bar = \w -> foldrM bar (head w) w | |
| foo = head >>= foldrM bar |
This file contains hidden or 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 ExistentialQuantification #-} | |
| import Data.List (unlines) | |
| data HasEq = forall a. (Eq a, Show a) => HasEq a | |
| data AnyIntegral = forall a. Integral a => Integral a | |
| data AnyTree x = forall a b. (Show a, Show b) => Tree x (AnyTree a) (AnyTree b) | Nil | |
| instance Show a => Show (AnyTree a) where | |
| show (Tree x a b) = show (x,(a,b)) | |
| show Nil = "Nil" |
This file contains hidden or 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
| class Comonad w => ComonadScan w where | |
| scanW :: (a -> w b -> a) -> a -> w b -> w a | |
| scanW f acc w = (duplicate w) | |
| instance ComonadScan Tree where | |
| scanW f acc w@(Node _ as) = let acc' = f acc w in Node acc' (map (scanW f acc') as) |
This file contains hidden or 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 NamedFieldPuns #-} | |
| {-# LANGUAGE ViewPatterns #-} | |
| import Grammar (BinOp, Identifier, Type, HashMap) | |
| import Typed | |
| import Control.Comonad | |
| import Control.Applicative (liftA2) | |
| data Expression t | |
| = BinOp {lhs :: Expression t, op :: BinOp, rhs :: Expression t, typ :: t} | |
| | MethodCall (Expression t) Identifier [Expression t] t |
This file contains hidden or 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
| -- Normal fixed point | |
| fix f = f (fix f) | |
| -- | Slow comonadic fixed point à la Kenneth Foner: | |
| pfix :: Comonad w => w (w a -> a) -> w a | |
| pfix = extend wfix | |
| -- | Comonadic fixed point à la Kenneth Foner: | |
| kfix :: ComonadApply w => w (w a -> a) -> w a | |
| kfix w = fix $ \u -> w <@> duplicate u |
This file contains hidden or 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
| funkyProduct lst = zipWith | |
| (*) | |
| (scanl (*) 1 lst) | |
| (scanr (*) 1 $ (tail lst)) | |
| --Prelude> funkyProduct [2,3,5,10] | |
| --[150,100,60,30] |
This file contains hidden or 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
| /* | |
| * T T C P . C | |
| * | |
| * Test TCP connection. Makes a connection on port 5001 | |
| * and transfers fabricated buffers or data copied from stdin. | |
| * | |
| * Usable on 4.2, 4.3, and 4.1a systems by defining one of | |
| * BSD42 BSD43 (BSD41a) | |
| * Machines using System V with BSD sockets should define SYSV. | |
| * |