I am trying to concatenate a String and a Char to produce a String in idris. This is the code
*Printf> :let e1 : String = "123"
*Printf> :let e2 : Char = 'f'
*Printf> :let e3 : String = e1 ++ pack [e2]
(input):1:9: When checking type of e3:
Can't disambiguate name: Prelude.List.::, Prelude.Stream.::, Data.Vect.::
(input):1:9:No type declaration for e3
*Printf>
I don't understand the error. What is the problem here? This is Idris 1
Check the types! You are trying to join two strings with ++. Is there a function by that name with the appropriate type? From the error, you could infer that ++ is used with list-like structures – that's why it mentions ::; that is probably involved in the definition of ++, but the type-checker can't find a function of that name applying to strings.
Absent a more specific function, you need to unpack the string, concat the character at the end, and repack:
e3 = pack (unpack e1 ++ [e2])
Related
In MS SQL, is there an operator that allows the matching of one or more character? (I'm curious about whether its implemented explicitly in T-SQL - other solutions are certainly possible, one of which I use in my question example below . . .)
I know in SQL, this could be explicitly implemented to varying degrees of success with the wildcard/like approach:
SELECT *
FROM table
-- finds letters aix and then anything following it
WHERE column LIKE 'aix_x%'
In Python, the '+' operator allows for this:
import re
str = "The rain in Spain falls mainly in the plain!"
#Check if the string contains "ai" followed by 1 or more "x" characters:
# finds 'ai' + one or more letters x
x = re.findall("aix+", str)
print(x)
if (x):
print("Yes, there is at least one match!")
else:
print("No match")
Check if the string contains "ai" followed by 1 or more "x" characters:
finds 'ai' + one or more letters x
If this is what you want, then:
where str like '%aix%'
does what you want.
If you want an underscore, then an underscore is a wildcard in LIKE expressions. Probably the simplest method in SQL Server is to use a character class:
where str like '%ai[_]x%'
another solution is:
where str like '%ai$_x%' escape '$'
I'm having trouble understanding what exactly a comparable is in Elm. Elm seems as confused as I am.
On the REPL:
> f1 = (<)
<function> : comparable -> comparable -> Bool
So f1 accepts comparables.
> "a"
"a" : String
> f1 "a" "b"
True : Bool
So it seems String is comparable.
> f2 = (<) 1
<function> : comparable -> Bool
So f2 accepts a comparable.
> f2 "a"
As I infer the type of values flowing through your program, I see a conflict
between these two types:
comparable
String
So String is and is not comparable?
Why is the type of f2 not number -> Bool? What other comparables can f2 accept?
Normally when you see a type variable in a type in Elm, this variable is unconstrained. When you then supply something of a specific type, the variable gets replaced by that specific type:
-- says you have a function:
foo : a -> a -> a -> Int
-- then once you give an value with an actual type to foo, all occurences of `a` are replaced by that type:
value : Float
foo value : Float -> Float -> Int
comparable is a type variable with a built-in special meaning. That meaning is that it will only match against "comparable" types, like Int, String and a few others. But otherwise it should behave the same. So I think there is a little bug in the type system, given that you get:
> f2 "a"
As I infer the type of values flowing through your program, I see a conflict
between these two types:
comparable
String
If the bug weren't there, you would get:
> f2 "a"
As I infer the type of values flowing through your program, I see a conflict
between these two types:
Int
String
EDIT: I opened an issue for this bug
Compare any two comparable values. Comparable values include String, Char, Int, Float, Time, or a list or tuple containing comparable values. These are also the only values that work as Dict keys or Set members.
taken from the elm docs here.
In older Elm versions:
Comparable types includes numbers, characters, strings,~~
lists of comparable things, and tuples of comparable things. Note that
tuples with 7 or more elements are not comparable; why are your tuples
so big?
This means that:
[(1,"string"), (2, "another string")] : List (Int, String) -- is comparable
But having
(1, "string", True)` : (Int, String, Bool) -- or...
[(1,True), (2, False)] : List (Int, Bool ) -- are ***not comparable yet***.
This issue is discussed here
Note: Usually people encounter problems with the comparable type when they try to use a union type as a Key in a Dict.
Tags and Constructors of union types are not comparable. So the following doesn't even compile.
type SomeUnion = One | Two | Three
Dict.fromList [ (One, "one related"), (Two, "two related") ] : Dict SomeUnion String
Usually when you try to do this, there is a better approach to your data structure. But until this gets decided - an AllDict can be used.
I think this question can be related to this one. Int and String are both comparable in the sense that strings can be compared to strings and ints can be compared to ints. A function that can take any two comparables would have a signature comparable -> comparable -> ... but within any one evaluation of the function both of the comparables must be of the same type.
I believe the reason f2 is confusing above is that 1 is a number instead of a concrete type (which seems to stop the compiler from recognizing that the comparable must be of a certain type, probably should be fixed). If you were to do:
i = 4 // 2
f1 = (<) i -- type Int -> Bool
f2 = (<) "a" -- type String -> Bool
you would see it actually does collapse comparable to the correct type when it can.
The set of string from the alphabet {j,k} where the string can be reversed and then all j's changed to k's and all k's changed to j's.
For example "jjkk" would be in the language because when you reverse it: "kkjj" and when you flip all of the characters to the other character: "jjkk"
"kjk" would not be in the language because when you reverse it: "kjk" (the same) and flipping the characters yields "jkj" which is not the same as the starting string.
The string can't be an odd length because then the middle character can't be flipped. Every ith character from the left that is a j must have a corresponding k i characters from the right. The same holds for ks on the left and js on the right. So:
S ::= ε | jSk | kSj
I have a bunch of longs that are sometimes string "INFINITY" or "NaN".
Assuming A is a record and B is a long:
I've tried doing...
FOREACH A GENERATE (B is not null?B:-1)
Though the above is not accurate as sometimes "B" apparently is a string.
Is there some conditional or compound conditional to check if it is not null and either 1) is not a string or 2) cast B such that i can make sure it is not null and does not start with "NaN" in a conditional?
My goal is to make it such that the long gets converted to a number (-1 if it is "NaN", or stay the same if it is not).
Describing A would show the following if exists, (or NaN if does not exist):
{
"B":28.2524232
}
Try this,
First load that long data as chararray format, then do conditions on it, then convert back into long. For example,
A = load 'data_file' as (B:chararray);
result1 = FOREACH A GENERATE (B matches '(.*)NaN(.*)'?'-1':(B matches '(.*)INFINITY(.*)'?'-1':B)) as B;
result2 = FOREACH result1 GENERATE (long)B;
Hope it should work and worked for me.
Maybe something like this :
FOREACH A GENERATE (B is not null ? (B matches 'NaN' OR B matches 'INFINITY' ? -1 : (int) B):-1)
Because of the "NaN" and the "INFINITY" pig may infer a bitearray or chararray, check the DESCRIBE as GoBrewers14 recommend.
Although you can LOAD with a schema and specify it as chararray and then convert as I did it :)
NB : the "B is not null" shouldn't be necessary but in case of ;)
So what I want, is for example to convert the letter 'a' into 97 (such as it is in the ASCII table), and then convert 67 into 'a'.
I actually perform a load of mathematics and stuff to the letter, treating it as binary number - so the transition is necessary.
However for special characters it is not working nicely.
char c = 'ÿ';
int i = int(c);
wchar_t wTemp = static_cast<wchar_t>(i);
wchar_t* w = &wTemp;
String^ newI = gcnew String(w);
That symbol is just a random one I found in an image (the type of character that will need to be read). It just comes out as a completely different symbol. I have no idea why, or what to do?
Characters above 0x7f (127) are probably converting to negative integer values. Maybe change c to unsigned:
unsigned char c = 'ÿ';
int i = c;
Your code doesn't look quite right to me though I didn't run it. Here is a good example from MSDN how to convert from and to wchar_t:
http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx
I don't believe there is anything special about 'special' characters.