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
-- Uso de "bind" | |
import Data.List.HT (chop) | |
import Control.Monad(liftM, foldM) | |
lineas :: IO ([[String]]) | |
lineas = | |
(liftM -- (String -> [[String]]) -> (IO (String) -> IO ([[String]])) | |
((map (chop (== ','))).lines)) -- String -> [[String]] | |
. readFile -- IO (String) |
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
-- número de pasos para aproximar -phi por punto fijo de x = 1/(x-1) | |
Prelude Graphics.Gnuplot.Simple> plotList [] $ | |
map (\x -> let | |
nums = iterate (\k -> 1/(k-1)) x in | |
(\(a,b,c) -> c) $ | |
head $ | |
dropWhile (\(a,b,c) -> a /= b) $ | |
zip3 (tail nums) nums [1..]) (map (/3000) [0..12000]) |
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
-- Ejemplo de construcción de melodía (serie y paralelo) en Haskore | |
-- Suena horrible, pero hace exactamente lo que tiene que hacer. | |
-- haskore-0.1 | |
-- fileFromGeneralMIDIMusic | |
import Haskore.Interface.MIDI.Render | |
-- a..g ("la" a "sol") | |
import Haskore.Melody |
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
Máquina de Turing | |
---------------------------- | |
Compilar con '-package parsec'; ejemplo de compilación: ' $ ghc -package parsec -o turing turing.lhs ' | |
El ejecutable recibe como primer argumento la descripción de una máquina de Turing, y como segundo | |
argumento una cadena inicial para la cinta. | |
Si la máquina finaliza escribe True si se alcanzó un estado de paro, False en otro caso. | |
En ambos casos escribe el estado final de la cinta, en el formato ([lado izquierdo],[lado derecho]) |
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
module Main where | |
data Registro = R { | |
valor :: Integer, | |
nombre :: String, | |
peso :: Float | |
} deriving Show | |
data Arbol a = Hoja | Rama a a deriving Show |
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
-- The Song that Never Ends | |
Prelude> let song = stanza ++ song where stanza = "This is the song that doesn't end, Yes, it goes on and on, my friend. Some people started singing it, not knowing what it was, and they'll continue singing it forever just because... " |
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
module Main where | |
import Control.Monad.State | |
import Control.Monad | |
-- funciones base del generador de programas al azar | |
import System.Random | |
import System.Random.Shuffle |
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
-- Forma directa de implementar una máquina de estado vía Control.Monad.State | |
-- Implementa acciones en secuencia; no espera caso final, ejecuta k veces la máquina | |
-- Modificado a partir de http://www.haskell.org/pipermail/beginners/2008-September/000275.html | |
module FibState where | |
import Control.Monad.State | |
import Control.Monad | |
-- ¿cual es el tipo de datos del estado? |
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
/* foldl en C con hilos */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
#include <unistd.h> | |
#include <math.h> |
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 Ratio | |
-- función lineal; x --> (a,b) = ax + b | |
type FL = (Ratio Integer, Ratio Integer) | |
-- Composición | |
-- x --> (a, b) · (c, d) = c(ax + b) + d = (acx) + (bc + d) | |
-- (a, b) · (c, d) = (ac, bc + d) |
OlderNewer