-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadme.html
263 lines (195 loc) · 8.38 KB
/
readme.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Paradigmas de Programación</title>
<link rel="stylesheet" href="./Resources/bright/style.css" type="text/css" charset="utf-8" media="screen">
<link rel="stylesheet" href="./Resources/default/style.css" type="text/css" charset="utf-8" media="screen">
<link rel="stylesheet" href="./Resources/default/print.css" type="text/css" charset="utf-8" media="print">
</head>
<body id="tm_webpreview_body" class="bright">
<div id="tm_webpreview_header">
<img id="gradient" src="./Resources/bright/images/header.png" alt="header">
<p class="headline">Paradigmas de Programación</p>
<p class="type">readme.markdown</p>
<img id="teaser" src="./Resources/bright/images/teaser.png" alt="teaser">
</div>
<div id="tm_webpreview_content" class="bright">
<h1>Haskell-IOS</h1>
<p>Aplicación demo para ejecutar códico Haskell desde dispositivos mobiles IOS</p>
<hr />
<h2>Integrantes</h2>
<ul>
<li>Ernesto Manuel Carrión Chumpitaz</li>
<li>Alejandro Aristizabal Londoño</li>
<li>Daniel Munera Sanchez</li>
</ul>
<h2>Profesor</h2>
<ul>
<li>Francisco Jose Correa Zabala</li>
</ul>
<h2>Introducción</h2>
<p>Este documento describe la instalación y el uso del GHC (Glasgow Haskell Compiler) en dispositivos IOS</p>
<h2>Instalación</h2>
<ul>
<li>Descargar e instalar <a href="http://haskell.org/ghc/">GHC standar</a></li>
<li>Extraer en el directorio raiz “/” el archivo <a href="http://projects.haskell.org/ghc-iphone/downloads/ghc-iphone-binary-1.6-sdk-4.2.tar.bz2">ghc-iphone.tar.bz</a></li>
</ul>
<hr />
<h2>Haskell Backend</h2>
<h3>Main.hs</h3>
<pre><code>{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls #-}
import Foreign.C.Types
foreign import ccall safe "openWindow" openWindow
:: IO CInt
foreign export ccall "fibonacci" fibonacci
:: Int -> Int
foreign export ccall "fac" fac
:: Int -> Int
fibonacci :: Int -> Int
fibonacci n = fibs !! n
where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
fac :: Int -> Int
fac 0 = 1
fac n | n > 0 = n * fac (n-1)
main = do
openWindow
return ()
</code></pre>
<h3>Haskel_IOS.cabal</h3>
<pre><code>Name: HaskellIOS
Version: 0.1
Synopsis: iPhone app in haskell
Description: iPhone app in haskell
Build-type: Simple
Cabal-Version: >= 1.6
Executable Haskell_IOS
Main-Is: Main.hs
Frameworks:
Foundation
UIKit
CoreGraphics
Build-Depends:
base >= 4
</code></pre>
<hr />
<h2>Configuración XCode</h2>
<h3>En el dispositivo - Desabilitar ‘Thumb Mode’</h3>
<ol>
<li>Abrir las propiedades del proyecto</li>
<li>En el Target del proyecto seleccionar el tab <strong>Build Settings</strong></li>
<li>Buscar por <strong>thumb</strong> y deseleccionar <strong>Compile for thumb</strong></li>
</ol>
<h3>Añadir Haskell Target</h3>
<p>El proyecto de Xcode debe construir automaticamente el proyecto Haskell, previamente se deben haber agregado a la raiz del proyecto el archivo <code>*.hs</code> y el archivo <code>*.cabal</code></p>
<ul>
<li>Seleccionar File > New > New Target</li>
<li>Seleccionar <strong>Other</strong> dentro del grupo <strong>Mac OSX</strong></li>
<li>Seleccionar <strong>External Build System</strong></li>
<li>Escribir <strong>Haskell</strong> como Product Name (o cualquier normbre de su preferencia)</li>
<li>Escribir <strong>/opt/iphone/bin/build-iphone-haskell.s</strong> en el campo <strong>Build Tool</strong></li>
<li>Establecer el Target <strong>Haskell</strong> como dependencia del proyecto:
<ul>
<li>Doble click en el Target principal del proyecto</li>
<li>Seleccionar el tab <strong>Build Phases</strong></li>
<li>Expandir la lista <strong>Target Dependencies</strong> y arrastrar el Targer <strong>Haskell</strong> hacia allí</li>
</ul></li>
</ul>
<h3>Construir Haskell Target</h3>
<p>Necesitamos compilar primero el Target <strong>Haskell</strong> para poder generar una librería con los fuentes de haskell para poder despues añadirla al proyecto.</p>
<ul>
<li>Seleccionar Product > Build al Target <strong>Haskell</strong></li>
<li>Doble click en el panel de errores y revisar que no haya ningún error en los fuentes de haskell. Correguir los errores hasta que no quede ningún error.</li>
<li>Es pobable que la compilación del proyecto principal falle, pero lo importante es que el Target <strong>Haskell</strong> compile correctamente.</li>
</ul>
<h3>Añadir libreria al proyecto</h3>
<p>Esto nos va a permitir ejecutar código haskell desde un FrontEnd <strong>Objective-C</strong> mediante un wrapper en <strong>C</strong></p>
<ul>
<li>Doble click en el Target principal del proyecto</li>
<li>Seleccionar el tab <strong>Build Phases</strong></li>
<li>Expandir la lista <strong>Link Binary With Libraries</strong></li>
<li>Añadir la librería generada anteriormente en el path definido por Xcode donde se guardan todos los Builds <strong>Build Dir</strong></li>
</ul>
<hr />
<h2>Haskell desde Objective-C</h2>
<h3>main.m</h3>
<pre><code>#import <UIKit/UIKit.h>
extern int Haskell_main(int argc, char* argv[]);
int main(int argc, char *argv[])
{
Haskell_main(argc, argv);
}
int doMain(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
int openWindow(void);
int openWindow() {
static char* args[2];
args[0] = "dummy";
args[1] = NULL;
return doMain(1, args);
}
</code></pre>
<h3>HaskellViewController.m</h3>
<pre><code>extern int fibonacci(int a1);
extern int fac(int n);
</code></pre>
<h3>HaskellViewController.m</h3>
<pre id="scroll_to_here" ><code>- (IBAction)fibPressed {
int i = [self.input_.text intValue];
int o = fibonacci(i);
self.output_.text = [NSString stringWithFormat:@"%d", o];
}
- (IBAction)facPressed {
int i = [self.input_.text intValue];
int o = fac(i);
self.output_.text = [NSString stringWithFormat:@"%d", o];
}
</code></pre>
<hr />
<h2>Concluciones</h2>
<ul>
<li><p>Lograr la ejecución de código <strong>Haskell</strong> desde <strong>Objective-C</strong> nos ha brindado una verdadera integración de paradigmas en una sola plataforma:</p>
<ul>
<li>Haskell: Funcional</li>
<li>Objective-C: Orientado a Objetos</li>
<li>C: Imperativo/Estructurado</li>
</ul></li>
<li><p>Gracias a la ejecución de código Haskell desde Objective-C hemos podido ampliar nuestro espectro de soluciones en la plataforma IOS, como también podemos mejorar ciertas tareas que tengan una naturaleza funcional, tales como:</p>
<ul>
<li>Inteligencia Artificial</li>
<li>Diseño de lenguajes de alto nivel</li>
</ul></li>
</ul>
<hr />
<h2>TODO</h2>
<ul>
<li>Ya que el Glasgow Haskell Compiler (GHC) se encarga de convertir código Haskell en <strong>C</strong> debe ser posible poder usar esta librería para ejecutar código Haskell desde dispositivos android usando el NDK (Native development Kit)</li>
<li>Al contar Android con una <strong>Scripting layer</strong> es posible ejecutar <strong>código Python</strong> lo cual nos podría permitir usar sus las caracteristicas funcionales de ese lenguaje</li>
<li>Investigar sobre posibilidades de ejecutar programas funcionales en los demás sistemas operativos de los smartphones restantes:
<ul>
<li>BlackBerry OS - RIM</li>
<li>Windows Phone 7 - Microsoft</li>
<li>Symbian - Nokia</li>
<li>Meego - Nokia/Intel</li>
</ul></li>
</ul>
<hr />
<h2>Referencias</h2>
<ul>
<li><a href="http://gergo.erdi.hu/blog/2011-02-13-developing_iphone_applications_in_haskell___a_tutorial/">Developing iphone applications in Haskell</a></li>
<li><a href="http://projects.haskell.org/ghc-iphone/downloads/GHC-iPhone.pdf">Iphone Port of GHC</a></li>
<li><a href="http://hoc.sourceforge.net/">A Haskell to Objective-C Binding</a></li>
<li><a href="http://tscheff.blogspot.com/2010/02/small-haskell-objective-c-interface.html">A small Haskell / Objective-C Interface</a></li>
<li><a href="http://www.haskell.org/haskellwiki/Using_Haskell_in_an_Xcode_Cocoa_project">Using Haskell in an XCode Cocoa Project</a></li>
<li><a href="http://www.haskell.org/haskellwiki/Calling_Haskell_from_C">Calling Haskell from C</a></li>
<li><a href="http://www.haskell.org/haskellwiki/Haskell_in_industry">Haskell in Industry</a></li>
</ul>
<script>window.location.hash = "scroll_to_here";</script>
</div>
</body>
</html>