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
In here, I will write each node as | |
[weight]number=expr | |
and, as a compact notation, multiple nodes with same weight | |
[w]n1=e1 [w]n2=e2 [w]n3=e3 | |
are denoted | |
[w]n1=e1 n2=e2 n3=e3 | |
I will trace execution of your algorithm applied to input {20}. | |
First, I register [0]1 and generate [1]2=1+1 |
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
-- Related to: http://stackoverflow.com/questions/16128645/ | |
-- Haskell source file I implemented the algorithm which is written in the question. | |
-- this program is written under GHC 7.4.2 @ Ubuntu 12.10, | |
-- requires mtl (Monad transformers) module. | |
-- To test this: | |
-- * place this file on a directory | |
-- * run GHCi there | |
-- * load NatSet module (:load NatSet) | |
-- * give some list of Int to printClosure function. | |
-- example: > printClosure [7, 20, 17, 100] |
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
-- simple test for NatSet.hs | |
-- | |
-- I did the performance test by running | |
-- $ time ./natset_perf | |
-- command, where natset_perf is compiled executable of this code. | |
import NatSet | |
import System.Random | |
import Control.Monad (forM_) |
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
(* definition of Tree *) | |
Inductive Tree : Set := | |
| leaf : Tree | |
| node : Tree -> Tree -> Tree. | |
(* definition of Domain *) | |
Inductive Domain : Set := | |
| I : Domain | |
| T : Domain | |
| sum : Domain -> Domain -> Domain |
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 GADTs #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-| | |
Module : SetMonad | |
Description : Set that is also Monad | |
This module provides the @Set@ type equipped with @Monad@ instance and most of set | |
operations provided in the @Data.Set@ module of @containers@ package. | |
The ability to handling any type is not \"free\". If there is no clue |
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 BangPatterns #-} | |
module Main where | |
main :: IO () | |
main = putStrLn "Compiles" | |
letBangPattern :: Int | |
letBangPattern = let !x = 1 + 2 in 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
Applicative laws (in terms of 'prod'): | |
prod :: Applicative f => f a -> f b -> f (a,b) | |
prod = liftA2 (,) | |
(1) Left unit: | |
pure a `prod` fb = fmap (a,) fb |
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 EmptyCase #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Data.Matchable( | |
-- * Matchable class | |
Matchable(..), | |
zipzipMatch, | |
traverseDefault, | |
eqDefault, |
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
During play around objective package, I noticed following type has interesting property. | |
> {-# LANGUAGE RankNTypes #-} | |
> {-# LANGUAGE GADTs #-} | |
> {-# LANGUAGE TypeOperators #-} | |
> {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} | |
> {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-} | |
> {-# LANGUAGE UndecidableInstances #-} | |
> | |
> import Control.Monad |
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 FlexibleContexts #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module AdHocInstances( | |
Group(..), | |
GroupExpr(), | |
adhocGroup | |
) where |
OlderNewer