Juan Pablo Yamamoto
jpyamamoto[at]ciencias.unam.mx
Lógica Computacional II. Semestre 2025-1.
:!stack build linear-base
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE NoImplicitPrelude #-}
import Prelude.Linear
id :: a -> a
id x = x
id :: a %1 -> a
id x = x
id 'a'
'a'
dup :: a -> (a, a)
dup x = (x, x)
dup' :: a %1 -> (a, a)
dup' x = (x, x)
<interactive>:4:6: error: • Couldn't match type ‘'Many’ with ‘'One’ arising from multiplicity of ‘x’ • In an equation for ‘dup'’: dup' x = (x, x)
Consumo lineal:
Int
, Char
, Float
.:t (+)
:t (*)
:t fst
swap :: (a, b) -> (b, a)
swap (x,y) = (y,x)
swap' :: (a, b) %1 -> (b, a)
swap' (x,y) = (y,x)
:t swap
:t swap'
data Par a b = Par a b
:t Par
swapPar :: Par a b %1 -> Par b a
swapPar (Par x y) = Par x x
:t swapPar
data List a = Empty | Cons a (List a)
head :: List a %1 -> a
head Empty = error "Vacía"
head (Cons x xs) = x