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
public static class MyExtensions | |
{ | |
public static T1 Fold<T1, T2>(this IEnumerable<T2> xs, Func<T1,T2,T1> func, T1 acc) | |
{ | |
if (xs.Count() == 0) return acc; | |
else return xs.Skip(1).Fold(func, func(acc, xs.First())); | |
} | |
public static bool AllSame<T>(this IEnumerable<T> xs) | |
{ | |
return xs.AllSame(x => x); |
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 | |
class Functor w => Comonad w where | |
extract :: w a -> a | |
duplicate :: w a -> w (w a) | |
extend :: (w a -> b) -> w a -> w b | |
data Stream a = Cons a (Stream a) | |
instance Functor Stream where |
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 | |
-----------Freq type---------------------- | |
data Freq = Freq { | |
frequency :: Int, | |
symbol :: Char | |
}deriving (Show) | |
instance Eq Freq where | |
a == b = (frequency a) == (frequency 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 RankNTypes #-} | |
-- Описание экзистенциального типа \exists a . (a, Integer -> a -> a, a -> (a, Integer)) | |
-- Это абстрактный тип данных, реализующий интерфейс стека с тремя операциями: | |
-- empty, push и pop. Для упрощения мы рассматриваем только целочисленный стек. | |
-- Здесь мы используем способ представления квантора существования в | |
-- интуиционистской логике 2-го порядка через квантор всеобщности: | |
-- \exists a . s = \forall b . ((\forall a . (s -> b)) -> b) | |
-- Соответственно, описание типа превращается в такое: | |
data AbstractStack = AS (forall b . (forall a . ( a -- Начальный стек |
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 LambdaCase #-} | |
import Data.List | |
data Term = Var String | App Term Term | Abs String Term | |
deriving (Eq, Ord) | |
data Type = Const | TVar String | Fun Type Type | |
deriving (Eq) |
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 java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.function.Supplier; | |
import java.util.stream.Stream; | |
import java.awt.font.NumericShaper.Range; | |
import java.util.*; | |
public final class Main { | |
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
mask [] [] = True | |
mask [] ['*'] = True | |
mask (x:xs) ['*'] = True | |
mask (x:xs) ms@('*':m:mss) = if m == x then mask xs mss else mask xs ms | |
mask (x:xs) (m:ms) = if m == x then mask xs ms else False | |
mask _ _ = 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
#include "stdafx.h" | |
#include <tchar.h> | |
#include <locale.h> | |
#include <windows.h> | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
using namespace std; |
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 DeriveFunctor #-} | |
import Data.Char(ord, chr) | |
data Fix f = Fx (f (Fix f)) | |
unFix :: Functor f => Fix f -> f (Fix f) | |
unFix (Fx x) = x | |
type Algebra f a = f a -> a |
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(game). | |
-compile(export_all). | |
-record(unitS, { | |
colour, | |
inventory=[], | |
rank=soldier, | |
hp=300}). |
OlderNewer