Skip to content

Instantly share code, notes, and snippets.

@joseanpg
joseanpg / mayorCapicuaP.hs
Created February 3, 2015 23:13
@Jose_A_Alonso Exercitium: Mayor capicúa producto de dos números de n cifras
-- www.glc.us.es/~jalonso/exercitium/mayor-capicua-producto-de-dos-numeros-de-n-cifras
mayorCapicuaP n = alpha 0 (t-1)
where
t = 10^n
b = div t 10
alpha a x | x > b = let a' = case beta x of
Just z -> max z a
Nothing -> a
in alpha a' (x-1)
@joseanpg
joseanpg / 01-menorProductoEscalarPorFuerza.hs
Last active August 29, 2015 14:14
@Jose_A_Alonso Exercitium: Mínimo producto escalar
-- http://www.glc.us.es/~jalonso/exercitium/minimo-producto-escalar/
import Data.List
-----------------------------------------------------------------------------------------
a <·> b = sum (zipWith (*) a b)
-----------------------------------------------------------------------------------------
@joseanpg
joseanpg / 01-particiones.hs
Last active August 29, 2015 14:14
@Jose_A_Alonso Exercitium: Particiones de enteros positivos
-- www.glc.us.es/~jalonso/exercitium/particiones-de-enteros-positivos/
zen :: ([a] -> [a]) -> [a] -> [a] -> [a]
zen f a b =
let a' = f a
b' = b ++ a
in case a' of
[] -> b'
_ -> zen f a' b'
@joseanpg
joseanpg / let_is_case.hs
Created February 6, 2015 12:32
case everything
module Letiscase where
data Tipo = TipoUno Int
| TipoDos Int
f (TipoUno x) = x
f (TipoDos x) = x
g t = case t of
TipoUno x -> x
newtype Mu a = In (Mu a -> a)
out :: Mu a -> (Mu a -> a)
out (In f) = f
omega = \f->(out f) f
psi = \h -> \f-> h ((out f) f)
yfix = \i-> omega (In (psi i))
factorial = yfix (\g-> \n->if n < 2 then 1 else n*( g (n-1)))
@joseanpg
joseanpg / helpingraf.hs
Created February 6, 2015 12:39
helpingraf.hs
import Data.List
-- alphabil = [0,0,0,0,1,1,1,2,2,2]
-- alphanob = [0,0,0,0,3,3,3,4,4,4]
alphabil = [0,0,0,1,1,2,2]
alphanob = [0,0,0,3,3,4,4]
betabil = {-nub-} (permutations alphabil)
betanob = {-nub-} (permutations alphanob)
@joseanpg
joseanpg / cardelli-definition.mod
Last active September 8, 2015 13:36
Basic Polymorphic Typechecking ~ Luca Cardelli 1987
(** http://lucacardelli.name/Papers/BasicTypechecking.pdf **)
(** Modula 2 **)
(***************************************************************************)
(**************************** DEFINITION MODULES ***************************)
(***************************************************************************)
(***************************************************************************)
DEFINITION MODULE ErrorMod;
PROCEDURE Msg(msg: ARRAY OF CHAR);
@joseanpg
joseanpg / 00-InferenciaDelTipoDeAff.hs
Last active February 12, 2016 18:03
PureScript: Determinando el js-tipo de Aff a Aff a = (a -> (), Error-> ()) -> Canceler )
https://github.com/slamdata/purescript-aff/blob/master/src/Control/Monad/Aff.purs
-- | A canceler is asynchronous function that can be used to attempt the
-- | cancelation of a computation. Returns a boolean flag indicating whether
-- | or not the cancellation was successful. Many computations may be composite,
-- | in such cases the flag indicates whether any part of the computation was
-- | successfully canceled. The flag should not be used for communication.
newtype Canceler e = Canceler (Error -> Aff e Boolean)