* [Caml-list] Doubt about function delaration parameter @ 2010-12-15 14:03 sieira 2010-12-15 15:14 ` Ashish Agarwal ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: sieira @ 2010-12-15 14:03 UTC (permalink / raw) To: caml-list Why doesn't this work?: type menu = {Textos: string list; Claves:string list};; let menu_principal = {Textos = ["Clientes";"Operaciones"];Claves = ["1";"2"]};; let rec pinta_menu = function {Textos = []; Claves = []} -> begin print_string ">"; (); end | {Textos = _; Claves = []} -> begin print_string "[EE] Error en el menu"; (); end | {Textos = []; Claves = _} -> begin print_string "[EE] Error en el menu"; (); end | {Textos = texto::textos; Claves = clave::claves} -> begin print_string texto^"Una dola\n"; pinta_menu({Textos = textos; Claves = claves}); end;; (Returns "This expression has type unit" ) While this does: let rec pinta_menu = function [],[] -> begin print_string ">"; (); end | _,[] -> begin print_string "[EE] Error en el menu"; (); end | [];_} -> begin print_string "[EE] Error en el menu"; (); end | texto::textos;clave::claves -> begin print_string texto^"Una dola\n"; pinta_menu({Textos = textos; Claves = claves}); end;; pinta_menu(menu_principal);; Note that Textos ean texts and Claves mean keys pinta_menu(menu_principal);; -- View this message in context: http://old.nabble.com/Doubt-about-function-delaration-parameter-tp30464033p30464033.html Sent from the Caml Discuss mailing list archive at Nabble.com. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Doubt about function delaration parameter 2010-12-15 14:03 [Caml-list] Doubt about function delaration parameter sieira @ 2010-12-15 15:14 ` Ashish Agarwal 2010-12-15 15:18 ` Esther Baruk 2010-12-15 16:15 ` sieira 2 siblings, 0 replies; 7+ messages in thread From: Ashish Agarwal @ 2010-12-15 15:14 UTC (permalink / raw) To: sieira; +Cc: caml-list [-- Attachment #1: Type: text/plain, Size: 2439 bytes --] Record field names must start with a lower case letter, so I cannot reproduce the error you mention. Also note you can simplify code like: print_string "foo"; (); to simply print_string "foo" Since print_string "foo" already returns unit, it is unnecessary to explicitly return unit after this. On Wed, Dec 15, 2010 at 9:03 AM, sieira <jaimito.hendrix@gmail.com> wrote: > > Why doesn't this work?: > > type menu = {Textos: string list; Claves:string list};; > > let menu_principal = {Textos = ["Clientes";"Operaciones"];Claves = > ["1";"2"]};; > let rec pinta_menu = function > {Textos = []; Claves = []} -> > begin > print_string ">"; > (); > end > | {Textos = _; Claves = []} -> > begin > print_string "[EE] Error en el menu"; > (); > end > | {Textos = []; Claves = _} -> > begin > print_string "[EE] Error en el menu"; > (); > end > | {Textos = texto::textos; Claves = clave::claves} -> > begin > print_string texto^"Una dola\n"; > pinta_menu({Textos = textos; Claves = claves}); > end;; > > > (Returns > > "This expression has type unit" > ) > > While this does: > > let rec pinta_menu = function > [],[] -> > begin > print_string ">"; > (); > end > | _,[] -> > begin > print_string "[EE] Error en el menu"; > (); > end > | [];_} -> > begin > print_string "[EE] Error en el menu"; > (); > end > | texto::textos;clave::claves -> > begin > print_string texto^"Una dola\n"; > pinta_menu({Textos = textos; Claves = claves}); > end;; > > pinta_menu(menu_principal);; > > > Note that Textos ean texts and Claves mean keys > > > pinta_menu(menu_principal);; > -- > View this message in context: > http://old.nabble.com/Doubt-about-function-delaration-parameter-tp30464033p30464033.html > Sent from the Caml Discuss mailing list archive at Nabble.com. > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 3710 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Doubt about function delaration parameter 2010-12-15 14:03 [Caml-list] Doubt about function delaration parameter sieira 2010-12-15 15:14 ` Ashish Agarwal @ 2010-12-15 15:18 ` Esther Baruk 2010-12-15 16:15 ` sieira 2 siblings, 0 replies; 7+ messages in thread From: Esther Baruk @ 2010-12-15 15:18 UTC (permalink / raw) To: sieira; +Cc: caml-list [-- Attachment #1: Type: text/plain, Size: 2318 bytes --] When you write : print_string texto^"Una dola\n"; you must put parenthesis around your string : print_string (texto^"Una dola\n"); Otherwise it means you concatenates a string with a thing of type unit. Esther 2010/12/15 sieira <jaimito.hendrix@gmail.com> > > Why doesn't this work?: > > type menu = {Textos: string list; Claves:string list};; > > let menu_principal = {Textos = ["Clientes";"Operaciones"];Claves = > ["1";"2"]};; > let rec pinta_menu = function > {Textos = []; Claves = []} -> > begin > print_string ">"; > (); > end > | {Textos = _; Claves = []} -> > begin > print_string "[EE] Error en el menu"; > (); > end > | {Textos = []; Claves = _} -> > begin > print_string "[EE] Error en el menu"; > (); > end > | {Textos = texto::textos; Claves = clave::claves} -> > begin > print_string texto^"Una dola\n"; > pinta_menu({Textos = textos; Claves = claves}); > end;; > > > (Returns > > "This expression has type unit" > ) > > While this does: > > let rec pinta_menu = function > [],[] -> > begin > print_string ">"; > (); > end > | _,[] -> > begin > print_string "[EE] Error en el menu"; > (); > end > | [];_} -> > begin > print_string "[EE] Error en el menu"; > (); > end > | texto::textos;clave::claves -> > begin > print_string texto^"Una dola\n"; > pinta_menu({Textos = textos; Claves = claves}); > end;; > > pinta_menu(menu_principal);; > > > Note that Textos ean texts and Claves mean keys > > > pinta_menu(menu_principal);; > -- > View this message in context: > http://old.nabble.com/Doubt-about-function-delaration-parameter-tp30464033p30464033.html > Sent from the Caml Discuss mailing list archive at Nabble.com. > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 4951 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Doubt about function delaration parameter 2010-12-15 14:03 [Caml-list] Doubt about function delaration parameter sieira 2010-12-15 15:14 ` Ashish Agarwal 2010-12-15 15:18 ` Esther Baruk @ 2010-12-15 16:15 ` sieira 2010-12-15 16:37 ` David Allsopp 2010-12-15 16:56 ` Raphael Proust 2 siblings, 2 replies; 7+ messages in thread From: sieira @ 2010-12-15 16:15 UTC (permalink / raw) To: caml-list Thanks for your replies. I'm now having some issue with Raphael's suggestion of using (string * string) list;; as the menu type. type menu = (string*string) list;; Results in a syntax error at the first parenthesis, while type menu = string*string;; fails too (at the asterisk) It seems like I'm missing something. Since according to the http://caml.inria.fr/pub/docs/manual-caml-light/node3.5.html documentantion , this sintax should be right. I'm using Camllight 0.81 by François Boisson running in Ubuntu lucid lynx -- View this message in context: http://old.nabble.com/Doubt-about-function-delaration-parameter-tp30464033p30465308.html Sent from the Caml Discuss mailing list archive at Nabble.com. ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [Caml-list] Doubt about function delaration parameter 2010-12-15 16:15 ` sieira @ 2010-12-15 16:37 ` David Allsopp 2010-12-15 16:56 ` Raphael Proust 1 sibling, 0 replies; 7+ messages in thread From: David Allsopp @ 2010-12-15 16:37 UTC (permalink / raw) To: sieira, caml-list sieira wrote: > Thanks for your replies. I'm now having some issue with Raphael's > suggestion of using (string * string) list;; as the menu type. > > > type menu = (string*string) list;; > > Results in a syntax error at the first parenthesis, while > > type menu = string*string;; > > fails too (at the asterisk) > > It seems like I'm missing something. Since according to the > http://caml.inria.fr/pub/docs/manual-caml-light/node3.5.html > documentantion , this sintax should be right. > > I'm using Camllight 0.81 by François Boisson running in Ubuntu lucid lynx People on this list will reasonably assume you're using Objective Caml unless you say otherwise - this should have been at the top of your original post. I don't know and don't have access to an installation of caml light but looking at http://caml.inria.fr/pub/docs/manual-caml-light/node3.9.html it would appear to me as though type abbreviations (which is what you're doing) need == in Caml Light: type menu == (string*string) list;; ... but I may well be wrong. David ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Doubt about function delaration parameter 2010-12-15 16:15 ` sieira 2010-12-15 16:37 ` David Allsopp @ 2010-12-15 16:56 ` Raphael Proust 2010-12-15 17:12 ` bluestorm 1 sibling, 1 reply; 7+ messages in thread From: Raphael Proust @ 2010-12-15 16:56 UTC (permalink / raw) To: caml-list; +Cc: sieira Le mercredi 15 décembre 2010 17:15:23, sieira a écrit : > Thanks for your replies. I'm now having some issue with Raphael's > suggestion of using (string * string) list;; as the menu type. > > > type menu = (string*string) list;; > > Results in a syntax error at the first parenthesis, while > > type menu = string*string;; > > fails too (at the asterisk) > > It seems like I'm missing something. Since according to the > http://caml.inria.fr/pub/docs/manual-caml-light/node3.5.html documentantion > , this sintax should be right. > > I'm using Camllight 0.81 by François Boisson running in Ubuntu lucid lynx I just installed Camllight and I encountered the problem as you. Because the type menu is just a shorter name for the complete type (string * string) list, you have to use: type menu == ( string * string ) list ;; (with two '=' signs) I don't know the exact rule about this. It might be close to the difference between 'type' and 'data' in Haskell. Good luck! -- _______ Raphaël ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Doubt about function delaration parameter 2010-12-15 16:56 ` Raphael Proust @ 2010-12-15 17:12 ` bluestorm 0 siblings, 0 replies; 7+ messages in thread From: bluestorm @ 2010-12-15 17:12 UTC (permalink / raw) To: raphlalou; +Cc: caml-list, sieira [-- Attachment #1: Type: text/plain, Size: 3133 bytes --] In Caml Light, the rule is the following : - if you declare a *new* type, such as a sum type ( Foo | Bar | Baz ) or a record type ( { foo : t; bar : t' } ), use "=" - if you just add an alias, a new name for an existing type, use "==" It is an alias if the right-hand side is a "type expression" (something you could use as is in a type annotation) It is interesting to note that, though less syntactically visible, the difference has not vanished in OCaml. OCaml type declarations may have two components, a type "equation" (~ alias for a type expression) and a "representation" (~ new ADT). For example the following is valid : type test = A.ty = A | B | C The type is declared to be an alias to the type "ty" in the module A, and also represented by the sum (A | B | C) : the definition is "re-exported", and an error will be thrown if A.ty is different from (A | B | C). It is occasionnaly nice to make representation explicit, while still keeping compatibility at the type level (the two types are considered equal by the type checker), and can also be avoid to "strenghten" an external dependency : if the upstream type definition changes, I'm sure my code will fail here instead of producing weird errors later. See the OCaml manual : http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html The difference between type declarations and alias/abbreviation is also significant for the semantics of "private types", which are an extension (or rather several successive extensions) to the OCaml language described here : http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc76 . On Wed, Dec 15, 2010 at 5:56 PM, Raphael Proust <raphlalou@gmail.com> wrote: > Le mercredi 15 décembre 2010 17:15:23, sieira a écrit : > > Thanks for your replies. I'm now having some issue with Raphael's > > suggestion of using (string * string) list;; as the menu type. > > > > > > type menu = (string*string) list;; > > > > Results in a syntax error at the first parenthesis, while > > > > type menu = string*string;; > > > > fails too (at the asterisk) > > > > It seems like I'm missing something. Since according to the > > http://caml.inria.fr/pub/docs/manual-caml-light/node3.5.html > documentantion > > , this sintax should be right. > > > > I'm using Camllight 0.81 by François Boisson running in Ubuntu lucid lynx > > I just installed Camllight and I encountered the problem as you. Because > the > type menu is just a shorter name for the complete type (string * string) > list, > you have to use: > type menu == ( string * string ) list ;; > > (with two '=' signs) > I don't know the exact rule about this. It might be close to the difference > between 'type' and 'data' in Haskell. > > Good luck! > -- > _______ > Raphaël > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > [-- Attachment #2: Type: text/html, Size: 4617 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-12-15 17:13 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-12-15 14:03 [Caml-list] Doubt about function delaration parameter sieira 2010-12-15 15:14 ` Ashish Agarwal 2010-12-15 15:18 ` Esther Baruk 2010-12-15 16:15 ` sieira 2010-12-15 16:37 ` David Allsopp 2010-12-15 16:56 ` Raphael Proust 2010-12-15 17:12 ` bluestorm
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox