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
| def hot_potato( queue, num ) | |
| def pass_potato potato_queue | |
| passer = potato_queue.pop | |
| potato_queue.insert( 0, passer ) | |
| potato_queue | |
| end | |
| def remove_looser( q, n ) | |
| list = q |
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
| -- You asked why the Haskell implementation is so much slower than the Ruby | |
| -- implementation. Before we do any comparision of X language to Y langage, | |
| -- we *must* do a complexity analysis ("Big-O"). We can't make any | |
| -- comparison of languages if the underlying algorithm isn't the same. | |
| -- | |
| -- Let's go through your code and analyze each function's contributing | |
| -- complexity. I'm putting your code in order from outer-most function to | |
| -- inner-most. You could do it vise-versa, but I think this helps | |
| -- illustrate this example best. |
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
| {}: # nix-env expects a function | |
| let | |
| # Get nixpkgs (in configuration.nix, use pkgs for this, but this file is standalone | |
| # to test it easier so we have to manually import nixpkgs) | |
| pkgs = import <nixpkgs> {}; | |
| # First, get the haskell packages from nixpkgs. In configuration.nix, you | |
| # can use pkgs.haskellngPackages for this of course. | |
| haskellngPackages = pkgs.haskellngPackages; |
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 ScopedTypeVariables #-} | |
| {-# LANGUAGE ExistentialQuantification #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| module Main where | |
| class FinalExpr a where | |
| intThing :: Int -> a | |
| stringThing :: String -> a |
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
| QUERY PLAN | |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Unique (cost=60.36..60.36 rows=1 width=28) (actual time=1.736..1.928 rows=2 loops=1) | |
| -> Sort (cost=60.36..60.36 rows=1 width=28) (actual time=1.735..1.815 rows=1278 loops=1) | |
| Sort Key: ds_sensor.datastream_id, temp."time" | |
| Sort Method: quicksort Memory: 148kB | |
| -> Nested Loop (cost=4.79..60.35 rows=1 width=28) (actual time=0.069..0.876 rows=1278 loops=1) | |
| -> Nested Loop (cost=4.79..40.33 rows=1 width=24) (actual time=0.047..0.107 rows=4 loops=1) | |
| -> Nested Loop (cost=4.64..39.68 rows=3 width=28) (actual time=0.034..0.079 rows=11 loops=1) | |
| -> Nested Loop (cost=4.49..39.04 rows=3 |
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 TemplateHaskell #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| import Control.Lens | |
| newtype Key model keytype = Key { unKey :: keytype } | |
| deriving (Show, Eq, Ord) |
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 FlexibleContexts #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| module Play where | |
| import Control.Monad.Free.VanLaarhovenE | |
| data Logging m = Logging |
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 FlexibleContexts #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| module Play where | |
| import Control.Monad.Free.VanLaarhovenE | |
| data Logging m = Logging |
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 FlexibleContexts #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| module NestedVL where | |
| import Control.Monad.Free.VanLaarhovenE | |
| data Logging m = Logging |
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 Rank2Types #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE DeriveFunctor #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| import Control.Arrow ((&&&)) | |
| import Data.Functor.Coyoneda | |
| import qualified Control.Monad.Free as F |
OlderNewer