Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Fwd: Re: Multiple letters between -> -> (Marcus Manning) 2. Re: Fwd: Re: Multiple letters between -> -> (Francesco Ariis) 3. How to parse hetero-list (Baa) 4. Re: Fwd: Re: Multiple letters between -> -> (Francesco Ariis) ---------------------------------------------------------------------- Message: 1 Date: Thu, 30 Nov 2017 12:37:12 +0100 From: Marcus Manning <icons...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> Message-ID: <08469b21-975c-f0e5-3911-ea1459cc9...@gmail.com> Content-Type: text/plain; charset="utf-8"; Format="flowed" Sorry again fo the long break, and thanks for explanation. Three Questions: 1.) Because (->) is defined with itself, it is also a Meta Type Constructor (TYPE == variable Rank Type == a Meta Type ?) 2.) How do I define a function which takes a 3-Kinded Type: let f:: h (g a); f a = a where g * -> * and h (*->*)->*, but it did not work as: h is deduced to be h * -> *. Prelude> let f:: h (g a); f a = a <interactive>:42:18: error: • Couldn't match type ‘h’ with ‘(->) (g a)’ ‘h’ is a rigid type variable bound by the type signature for: f :: forall (h :: * -> *) (g :: * -> *) a. h (g a) at <interactive>:42:5-15 Expected type: h (g a) Actual type: g a -> g a • The equation(s) for ‘f’ have one argument, but its type ‘h (g a)’ has none • Relevant bindings include f :: h (g a) (bound at <interactive>:42:18) What can I do? 3.) Is there any tool in Haskel where I can see which function parameter is bound to the given input, for instance something like a function showBinds: showBinds const (\c -> "s") (\(b,c) -> "c") Prelude> Param a gets (\c -> "s") b gets (\(b,c) -> "c") This is a simple example, but it gets more complicated with massive use of autocurrying. On 11/25/2017 05:39 PM, Francesco Ariis wrote: > On Sat, Nov 25, 2017 at 04:19:04PM +0100, Marcus Manning wrote: >> But why I can call g with Just: >> >> >> let g :: h a b -> h a b; g a = a >> >> g Just >> >> but Just is a->Maybe a > Because (->) is a type constructor itself, just with > convenient infix syntax: > > λ> :k (->) > (->) :: TYPE q -> TYPE r -> * > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171130/282dfdf7/attachment-0001.html> ------------------------------ Message: 2 Date: Thu, 30 Nov 2017 12:49:10 +0100 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> Message-ID: <20171130114910.2m6c6yzlyegod...@x60s.casa> Content-Type: text/plain; charset=utf-8 Hello Marcus, On Thu, Nov 30, 2017 at 12:37:12PM +0100, Marcus Manning wrote: > 2.) How do I define a function which takes a 3-Kinded Type: > > let f:: h (g a); f a = a > > where g * -> * and h (*->*)->*, but it did not work as: > > h is deduced to be h * -> *. h hasn't got kind * -> * -> *, as Maybe hasn't got kind * -> * -> * but * -> *. A simple type constructor like the one you are searching for is Either λ> :k Either Either :: * -> * -> * or a tuple λ> :k (,) (,) :: * -> * -> * ------------------------------ Message: 3 Date: Thu, 30 Nov 2017 14:08:28 +0200 From: Baa <aqua...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] How to parse hetero-list Message-ID: <20171130140828.6404b219@Pavel> Content-Type: text/plain; charset=US-ASCII Hello, All! I have types A, B, C... They have instances of class Read, Show, SomethingElse, ... I want to keep them as one collection. For example, I can use such datatype for it: data Tags = forall a. Read a => Tags [a] Now I want to parse "some-string" into A or B or C or ... but without to create type's sum of A|B|C|...! All those types have `Read` instance but Haskell will not find what instance to use, right? How to parse string with alternatives where each alternative returns `ReadP A` or `ReadP B`, etc? My intuition is that I should make `x <|> y <|> z <|> ...` where x,y,z - parses string into A, B, C, ... so they are expressions like `readPrec :: ReadPrec A`, etc. But how to pass types into such expression? I must to make expression folding (with `<|>`) `readPrec::someType`, where `someType` is item of types list `{A, B, C, ...}` May be it's possible to be done with HList-like types, like: HSet, HVect or similar, but I don't know: - how to iterate/fold over types - I'm not sure that HSet/HVect keeps types (like `A ::: B ::: C ::: ...`) My idea is to have some function which can parse string into one of A|B|C|... with call like: myParse "some-string" :: (Something A ::: B ::: C ::: D) (suppose `:::` is type-level "cons"). So, `myParse` is polymorphic and it can fold/iterate over type-list items (to call appropriate `readPrec`). Is it even possible? In languages with reflection I can pass list of types (type - is usual value) and call type's methods, but how to solve similar in Haskell? === Best regards, Paul ------------------------------ Message: 4 Date: Thu, 30 Nov 2017 13:13:11 +0100 From: Francesco Ariis <fa...@ariis.it> To: Marcus Manning <icons...@gmail.com> Cc: beginners@haskell.org Subject: Re: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> Message-ID: <20171130121311.5r4wgg3rseuom...@x60s.casa> Content-Type: text/plain; charset=utf-8 On Thu, Nov 30, 2017 at 12:55:07PM +0100, Marcus Manning wrote: > But Either is not (*->*)->*, instead it is *->(*->*). Is (*->*)->* > expressable in Haskell functions? Yes, with an appropriate data declaration: λ> data FooType a = FooCons (a Int) λ> :k FooType FooType :: (* -> *) -> * ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 113, Issue 28 ******************************************