How can I remove comments from a string given that dhall is typed e.g. "foo" -> foo?
@Michael-Kateregga do you have an example of how you'd want to remove the quotes?
In general you could use dhall-to-text to output strings. E.g.:
$ dhall-to-text <<< '"foo"' # note that this is a Dhall string
foo
Yes that works fine in bash, same as dhall-to-bash, do you know how I could use these executables inside inside dhall repl?
Reason: I need to create a config of the sort:
\(fun : Text) ->
let concat = https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/Text/concat
in let flink = "https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/List"
in let exactfun = concat [ "${flink}", "/", "${fun}" ]
in dhall-to-text <<< exactfun
I want to create a config that takes a string e.g. "map" so that I don't always have to type:
let map = https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/List/map
whenever I need to use any of the List comprehensions e.g. map in this case.
then I will just call
./config "map" Natural Bool Natural/even [2,4,3,6,7]
What you are trying to do is metaprogramming (that is turning arbitrary strings to symbols), which Dhall doesn’t support.
You can import the whole Prelude as attribute set(s), see https://github.com/dhall-lang/Prelude/blob/master/package.dhall
@f-f and @Profpatsch thank you for your responses, @Profpatsch importing the whole Prelude will allow me do, for instance:
let Prelude = https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/package.dhall in
Prelude.List.map …
which is great. This will work just fine. Thank you!!
I actually get error 404 when I do:
let Prelude = https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/package.dhall in
Prelude.List.map …
I think you can try the url https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/package.dhall
@Michael-Kateregga yes, the Prelude official location has moved from IPFS to Github: https://github.com/dhall-lang/Prelude
Thanks guys but I tried the following and still didn't succeed:
let x = https://github.com/dhall-lang/Prelude/package.dhall in x.'List'.map Natural Bool Natural/even [4,7,9,2]
I should get [True, False, False, True] as output.
Hi All, this works fine:
let prelude = https://ipfs.io/ipfs/QmcTbCdS21pCxXysTzEiucDuwwLWbLUWNSKwkJVfwpy2zK/Prelude/List/map
in prelude Natural Bool Natural/even [4,7,9,2]
Thanks for your time!
Sorry guys for coming back on this issue.
I just wanted to understand why this works:
https://ipfs.io/ipfs/QmcTbCdS21pCxXysTzEiucDuwwLWbLUWNSKwkJVfwpy2zK/Prelude/List/map Natural Bool Natural/even [4,7,9,2]
or this
https://raw.githubusercontent.com/dhall-lang/Prelude/302881a17491f3c72238975a6c3e7aab603b9a96/List/map Natural Bool Natural/even [4,7,9,2]
but this doesn't yet they are the same links:
https://github.com/dhall-lang/Prelude/tree/master/List/map Natural Bool Natural/even [4,7,9,2]
It looks like I need some kind of access key i.e. 302881a17491f3c72238975a6c3e7aab603b9a96 or QmcTbCdS21pCxXysTzEiucDuwwLWbLUWNSKwkJVfwpy2zK
What I really want to do is to write a function based on https://raw.githubusercontent.com/dhall-lang/Prelude/302881a17491f3c72238975a6c3e7aab603b9a96/List that I can just feed map ..., fold ..., concat ... etc as inputs and obtain the corresponding output.
@Michael-Kateregga https://github.com/dhall-lang/Prelude/tree/master/List/map points to an HTML-page (the Github UI), not a dhall file. Whay you want is the raw version at https://raw.githubusercontent.com/dhall-lang/Prelude/master/List/map.
Thanks @Profpatsch.
I managed to do the following:
so I just established the config:
{ Bool =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Bool/package.dhall
, Double =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Double/package.dhall
, Function =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Function/package.dhall
, Integer =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Integer/package.dhall
, List =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/List/package.dhall
, Natural =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Natural/package.dhall
, Optional =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Optional/package.dhall
, JSON =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/JSON/package.dhall
, Text =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Text/package.dhall
}
which I can then use in dhall repl on my local machine as, for example:
let x = ./config in x.List.map Natural Bool Natural/even
[4,3,21,4,7,45,7]
However, Is there a way I can avoid the repetition of
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude
in the config above by may be setting it to y =
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Bool/package.dhall
?
Regards,
On Tue, Oct 9, 2018 at 12:37 PM Profpatsch notifications@github.com wrote:
@Michael-Kateregga https://github.com/Michael-Kateregga
https://github.com/dhall-lang/Prelude/tree/master/List/map points to an
HTML-page (the Github UI), not a dhall file. Whay you want is the raw
version at
https://raw.githubusercontent.com/dhall-lang/Prelude/master/List/map.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dhall-lang/dhall-haskell/issues/626#issuecomment-428144187,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AeXmOsonTSYZOZTINlOxgidmodeiIlg8ks5ujHyBgaJpZM4XMXKE
.
Yeah, it already exists! :smile:
let prelude = https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/package.dhall
in prelude.`List`.map Natural Bool Natural/even [4,3,21,4,7,45,7]
being https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/package.dhall
{ `Bool` =
./Bool/package.dhall
, `Double` =
./Double/package.dhall
, Function =
./Function/package.dhall
, `Integer` =
./Integer/package.dhall
, `List` =
./List/package.dhall
, `Natural` =
./Natural/package.dhall
, `Optional` =
./Optional/package.dhall
, JSON =
./JSON/package.dhall
, `Text` =
./Text/package.dhall
}
@jneira thanks but that doesn't work for me for some reason. I think there is an issue with the ...deps/Prelude/Optional/concat file.
When I run your command I get the following error:
↳ https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/package.dhall
↳ https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Optional/package.dhall
↳ https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Optional/concat
a : Type
x : Optional (Optional a)
Error: Unbound variable
None
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude/Optional/concat:26:14
When I comment out the following, that's when I get something out i.e.
-- Optional = ./Optional/package.dhall
Oh, sorry, it seems you are using a release version instead master of dhall-haskell, None has been added recently.
The right url would be https://raw.githubusercontent.com/dhall-lang/Prelude/v2.0.0/package.dhall if you are using the latest release version of dhall-haskell 1.17.0 (see https://github.com/dhall-lang/dhall-haskell/releases)
You can check the dhall executable version with dhall version
@jneira yes that's right. I'm using v1.17.0. Ok great I will just comment it out for now.
Thanks a stack!
You are welcome! and thanks for trying dhall
Just for completeness,
let prelude = https://raw.githubusercontent.com/dhall-lang/Prelude/v2.0.0/package.dhall
in prelude.`List`.map Natural Bool Natural/even [4,3,21,4,7,45,7]
should work as-is with your dhall executable
Thanks @jneira yes its fine.
@jneira I noticed these imports are not snappy speed-wise.
You can make dhall saves a cache version of any import adding the sha256 of the file imported (and dhall does it for you with dhall freeze) so succesive uses of the imported file will be faster (i am on windows):
C:\dhall-haskell>type test.dhall
let prelude = https://raw.githubusercontent.com/dhall-lang/Prelude/v2.0.0/package.dhall
in prelude.`List`.map Natural Bool Natural/even [4,3,21,4,7,45,7]
C:\dhall-haskell>dhall-1.17.0 freeze < test.dhall > test-hashed.dhall
C:\dhall-haskell>type test-hashed.dhall
let prelude =
https://raw.githubusercontent.com/dhall-lang/Prelude/v2.0.0/package.dhall sha256:4de4adaa8b63ec74998dbb2f3c09bc22f6ed85434d8e747b0b99805f5d2b8953
in prelude.`List`.map Natural Bool Natural/even [ 4, 3, 21, 4, 7, 45, 7 ]
C:\dhall-haskell>timer "dhall-1.17.0 < test-hashed.dhall"
14:59:55,43
[ True, False, False, True, False, False, False ]
14:59:57,06
C:\dhall-haskell>timer "dhall-1.17.0 < test-hashed.dhall"
15:00:03,48
[ True, False, False, True, False, False, False ]
15:00:03,55
@Michael-Kateregga: Also, if you use the version on master it is much faster in general. I will be cutting a new release soon
Thank you @jneira and @Gabriel439
@Gabriel439 when I use the master i.e.
https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude
That's when I get the error:
↳ ./Prelude_config_repo2
↳ https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/PreludeHttpExceptionRequest Request {
host = "raw.githubusercontent.com"
port = 443
secure = True
requestHeaders = []
path = "/dhall-lang/dhall-haskell/master/Prelude"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
(StatusCodeException (Response {responseStatus = Status {statusCode = 404, statusMessage = "Not Found"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Security-Policy","default-src 'none'; style-src 'unsafe-inline'; sandbox"),("Strict-Transport-Security","max-age=31536000"),("X-Content-Type-Options","nosniff"),("X-Frame-Options","deny"),("X-XSS-Protection","1; mode=block"),("X-GitHub-Request-Id","4C40:356E:218CDB:25C411:5BBD9043"),("Content-Length","15"),("Accept-Ranges","bytes"),("Date","Wed, 10 Oct 2018 05:38:12 GMT"),("Via","1.1 varnish"),("Connection","keep-alive"),("X-Served-By","cache-cpt19521-CPT"),("X-Cache","MISS"),("X-Cache-Hits","0"),("X-Timer","S1539149892.947118,VS0,VE250"),("Vary","Authorization,Accept-Encoding"),("Access-Control-Allow-Origin","*"),("X-Fastly-Request-ID","ec5c6132997df18124d6e4078fd9223ba577e39f"),("Expires","Wed, 10 Oct 2018 05:43:12 GMT"),("Source-Age","0")], responseBody = (), responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}) "404: Not Foundn")
⊢ let x = ./Prelude_config_repo2 in x.List.map Natural Bool Natural/even [ 4, 3, 21, 4, 7, 45, 7 ]
But the link by @jneira i.e.
https://raw.githubusercontent.com/dhall-lang/Prelude/v2.0.0/package
works fine.
@Gabriel439 Ok I get it now, https://raw.githubusercontent.com/dhall-lang/dhall-haskell/master/Prelude leads to directories yet https://raw.githubusercontent.com/dhall-lang/Prelude/v2.0.0/package is the actual explicit file.
@jneira the sha256X hashing is amazing, the import is extremely fast now. Thanks!!!!